跳转到内容

User:Xiplus/Twinkle-dev.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
 * +-------------------------------------------------------------------------+
 * |                         === 警告:請勿使用 ===                          |
 * |                    穩定版:[[User:Xiplus/Twinkle.js]]                  |
 * |                  此工具為本人測試用,功能可能會常常修改                 |
 * |                     且不保證穩定性,其他問題請留言                      |
 * +-------------------------------------------------------------------------+
 */

// 修改自[[Special:PermaLink/45972864]]
(function () {
    /* 反importScript */
    var whitelist = ["Xiplus", "A2093064", "A2093064-test", "A2093064-bot"];
    if(whitelist.indexOf(mw.config.get('wgUserName')) === -1) {
        alert("請勿importScript User:Xiplus/Twinkle-dev.js!可能有未預期的危害發生。請改使用[[User:Xiplus/Twinkle.js]]。");
        return;
    }

    // var VERSION = '3d1d3e5';
    // var PREFIX = 'User:Xiplus/Twinkle/';
    var rebuildcache = true;
    var tests = [];

    var ajax = function (title) {
        return $.ajax({
            url: 'https://xiplus.ddns.net/twinkle/' + title,
            dataType: 'text',
        });
    };

    var load = function (p) {
        var done = function (data) {
            // if (rebuildcache || !localStorage['A64Twinkle_' + p.name]) {
            //     localStorage['A64Twinkle_' + p.name] = data;
            // }
        };
        if (localStorage['A64Twinkle_' + p.name] && !rebuildcache) {
            return $.Deferred().resolve(localStorage['A64Twinkle_' + p.name]);
        } else {
            if (p.test) {
                return ajax(p.name).done(done);
            } else {
                return ajax('MediaWiki:Gadget-' + p.name).done(done);
            }
        }
    };

    var message = function (text) {
        console.log('[A64Twinkle]', text);
    //    $('#simpleSearch input[type="search"]').attr('placeHolder', text);
    };

    tests.push({name: 'morebits.js',             test: true});
    tests.push({name: 'twinkle.js',              test: true});
    tests.push({name: 'modules/twinklearv.js',           test: true});
    tests.push({name: 'modules/twinklewarn.js',          test: true});
    tests.push({name: 'modules/friendlyshared.js',       test: true});
    tests.push({name: 'modules/friendlytag.js',          test: true});
    tests.push({name: 'modules/friendlytalkback.js',     test: true});
    tests.push({name: 'modules/twinklebatchdelete.js',   test: true});
    tests.push({name: 'modules/twinklebatchundelete.js', test: true});
    tests.push({name: 'modules/twinkleblock.js',         test: true});
    tests.push({name: 'modules/twinkleclose.js',         test: true});
    tests.push({name: 'modules/twinkleconfig.js',        test: true});
    tests.push({name: 'modules/twinklecopyvio.js',       test: true});
    // tests.push({name: 'modules/twinkledelimages.js',     test: true});
    tests.push({name: 'modules/twinklediff.js',          test: true});
    tests.push({name: 'modules/twinklefluff.js',         test: true});
    tests.push({name: 'modules/twinkleimage.js',         test: true});
    tests.push({name: 'modules/twinkleprotect.js',       test: true});
    tests.push({name: 'modules/twinklespeedy.js',        test: true});
    tests.push({name: 'modules/twinklestub.js',        test: true});
    tests.push({name: 'modules/twinkleunlink.js',        test: true});
    tests.push({name: 'modules/twinklexfd.js',           test: true});

    mw.loader.using(['mediawiki.user', 'mediawiki.util', 'mediawiki.Title', 'jquery.ui', 'jquery.tipsy']).done(function () {
        mw.loader.load('https://zh.wikipedia.org/w/index.php?title=User:Xiplus/Twinkle/morebits.css&action=raw&ctype=text/css', 'text/css');
        
        var i=0;
        var finished = 0;
        var code = [];

        // all
        message('Loading A64TW...');
        var promises = [];
        var done = function (x) {
            return function (data) {
                finished++;
                // message('Loading A64TW... (' + finished + '/' + tests.length + ')');
                code[x] = data;
            };
        };
        for (i=0; i<tests.length; i++) {
            promises.push(load(tests[i]).done(done(i)));
        }
        $.when.apply($, promises).done(function () {
            // localStorage.A64Twinkle_version = VERSION;
            eval(code.join('\n;\n'));
            message('Twinkle Done');
        });
    });
})();