跳转到内容

User:WQL-Twinkle/twinkle.js

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

(function () {
    if (mw.config.get('wgServerName') !== 'zh.wikipedia.org') {
        mw.notify(wgULS('Twinkle错误:只能用于中文维基百科。', 'Twinkle錯誤:只能用於中文維基百科。'));
        return;
    }

    var groups = mw.config.get('wgUserGroups');
    if (groups.indexOf('autoconfirmed') === -1 && groups.indexOf('confirmed') === -1) {
        mw.notify(wgULS('Twinkle错误:只有自动确认用户能够使用Twinkle。', 'Twinkle錯誤:只有自動確認用戶能夠使用Twinkle。'));
        return;
    }

    var VERSION = '4d4098b';
    var PREFIX = 'User:WQL-Twinkle/';
    var rebuildcache = localStorage.fakeTwinkle_version !== VERSION;
    var tests = [];

    var ajax = function (title) {
        return $.ajax({
            url: mw.config.get('wgScript') + '?title=' + title + '&action=raw&ctype=text/javascript',
            dataType: 'text',
        });
    };

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

    var message = function (text) {
        console.log('[FakeTwinkle]', 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: 'twinklearv.js',           test: true});
    tests.push({name: 'twinklewarn.js',          test: true});
    tests.push({name: 'friendlyshared.js',       test: true});
    tests.push({name: 'friendlytag.js',          test: true});
    tests.push({name: 'friendlytalkback.js',     test: true});
    tests.push({name: 'twinklebatchdelete.js',   test: true});
    tests.push({name: 'twinklebatchundelete.js', test: true});
    tests.push({name: 'twinkleblock.js',         test: true});
    tests.push({name: 'twinkleclose.js',         test: true});
    tests.push({name: 'twinkleconfig.js',        test: true});
    tests.push({name: 'twinklecopyvio.js',       test: true});
    tests.push({name: 'twinkledelimages.js',     test: true});
    tests.push({name: 'twinklediff.js',          test: true});
    tests.push({name: 'twinklefluff.js',         test: true});
    tests.push({name: 'twinkleimage.js',         test: true});
    tests.push({name: 'twinkleprotect.js',       test: true});
    tests.push({name: 'twinklespeedy.js',        test: true});
    tests.push({name: 'twinkleunlink.js',        test: true});
    tests.push({name: '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/zhwiki/w/index.php?title=User:WQL-Twinkle/morebits.css&action=raw&ctype=text/css', 'text/css');
        
        var i=0;
        var finished = 0;
        var code = [];

        // all
        message('Loading FakeTW...');
        var promises = [];
        var done = function (x) {
            return function (data) {
                finished++;
                //message('Loading FakeTW... (' + 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.fakeTwinkle_version = VERSION;
            eval(code.join('\n;\n'));
            message('Twinkle Done');
        });
    });
})();