User:Hat600/script/roads.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

//<nowiki>
/* 各项数据排列:名称、走向描述、起点、起点连接道路、终点、终点连接道路、长度、始建年份、扩建年份及描述 */
;(function($){
 
    // UI
    var fixitem = '<div style="position: fixed; bottom: 0; left: 0; width: 100%; height: 30%; z-index: 21; background: #FFFFFF; border-top: 2px solid black; padding: 2em;"><button id="CRgobutton1">Go</button><button id="CRskipbutton">Skip</button></div>';
    $('#bodyContent').append(fixitem);
    $('.wikitable tbody').children('tr:first-child').css('background-color', '#FFFF00').attr('id', 'CRonhold');
 
    $('#CRskipbutton').bind('click', function(){
        $('#CRonhold').remove();
        $('.wikitable tbody').children('tr:first-child').css('background-color', '#FFFF00').attr('id', 'CRonhold');
    });
 
    $('#CRgobutton1').bind('click', function(){
        var CRarticletitle = $('#CRonhold').children('td:eq(0)').text()
        var CRNSEW = $('#CRonhold').children('td:eq(1)').text()
        var CRstart = $('#CRonhold').children('td:eq(2)').text()
        var CRstartlink = $('#CRonhold').children('td:eq(3)').text()
        var CRend = $('#CRonhold').children('td:eq(4)').text()
        var CRendlink = $('#CRonhold').children('td:eq(5)').text()
        var CRlength = $('#CRonhold').children('td:eq(6)').text()
        var CRstartyear = $('#CRonhold').children('td:eq(7)').text()
        var CRextyear = $('#CRonhold').children('td:eq(8)').text()
        var wikitext = '\'\'\'' + CRarticletitle + '\'\'\'是一条位于[[北京市]][[海淀区]]的道路,' + CRNSEW + '。该路' + CRstart + ',' + CRstartlink + ',' + CRend + ',' + CRendlink + '。全长' +  CRlength + '。' + CRstartyear + ',' + CRextyear + '<ref>{{cite book|title=《北京志·海淀区志》|isbn=7-200-05091-1|author=北京市地方志编纂委员会|location=北京|publisher=北京出版社|year=2004|pages=642-644}}</ref>。\n== 参考资料 ==\n{{reflist}}\n[[Category:海淀区]]\n[[Category:北京道路]]'

        editToken = mw.user.tokens.get( 'editToken' );
        $.ajax({
            url: 'https://zh.wikipedia.org/w/api.php',
            type: 'POST',
            data: {
            format: 'xml',
            action: 'edit',
            title: CRarticletitle,
            text: wikitext,
            summary: '建立新条目:北京道路',
            minor: true,
            bot: 1,
            createonly: 1,
            token: editToken
            },
            success: function(data){
                console.log("success");
            }
        });
        $('#CRonhold').remove();
        $('.wikitable tbody').children('tr:first-child').css('background-color', '#FFFF00').attr('id', 'CRonhold');
    });
})(jQuery);
//</nowiki>