User:逆襲的天邪鬼/Twinkle-lzh/loader.js

// 載入自己修改的Twinkle

(function {    var groups = mw.config.get('wgUserGroups');    if (groups.indexOf('autoconfirmed') === -1 && groups.indexOf('confirmed') === -1) {        console.error('Twinkle错误：只有自动确认用户能够使用Twinkle. ');       return;    }

if (!localStorage.fakeTwinkle) { localStorage.fakeTwinkle = {}; }

var VERSION = '7788db8-hack0'; var PREFIX = 'User:逆襲的天邪鬼/Twinkle-lzh/'; // var rebuildcache = localStorage.fakeTwinkle.version !== VERSION; var rebuildcache = true; 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[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) { //   $('#simpleSearch input[type="search"]').attr('placeHolder', text); };

tests.push({name: 'morebits.js',            test: true}); tests.push({name: 'Twinkle.js',             test: true}); tests.push({name: 'twinklewarn.js',         test: true}); tests.push({name: 'friendlytag.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: 'twinklediff.js',         test: true}); tests.push({name: 'twinklefluff.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.RegExp', 'mediawiki.Title', 'jquery.ui.dialog', 'jquery.tipsy']).done(function {        mw.loader.load(mw.config.get('wgScript') + '?title=' + PREFIX + 'morebits.css' + '&action=raw&ctype=text/css', 'text/css');        var i=0;        var finished = 0;        var code = [];

// all message('Loading TW...'); var promises = []; var done = function (x) { return function (data) { finished++; message('Loading TW... (' + 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');        }); }); });