User:Gomdoli/TwinkleGlobal.js

/** * Forked from https://meta.wikimedia.org/w/index.php?oldid=20514941 * @see User:ChipWolf/TwinkleGlobal * @author wm:User:逆襲的天邪鬼 * @author User:ChipWolf * @author wm:User:Xiplus * @author wm:User:WhitePhosphorus * @author User:Gomdoli4696 */

(function {

var VERSION = '2020-10-08 00:00:00'; var PREFIX = 'User:Gomdoli4696/Twinkle/'; var rebuildcache = localStorage.Twinkle_global_cwlf_version !== VERSION; var tests = []; var api;

var ajax = function(title) { return api.get({		'action': 'query',		'format': 'json',		'prop': 'revisions',		'titles': title,		'rvprop': 'content'	}).then(function(data) {		for (var key in data.query.pages) { // eslint-disable-line guard-for-in, no-unreachable-loop			return data.query.pages[key].revisions[0]['*'];		}	}); };

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

var message = function(text) { console.log('[Twinkle_global_cwlf]', text); // eslint-disable-line no-console //   $('#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});

function main { message(mw.config.get('wgServer')); message(mw.config.get('wgDBname')); if (mw.config.get('wgServer') === 'https://meta.miraheze.org') { api = new mw.Api; } else { api = new mw.ForeignApi('https://meta.miraheze.org/api.php'); }

mw.loader.load('https://meta.miraheze.org/w/index.php?title=User:Gomdoli4696/Twinkle/morebits.css&action=raw&ctype=text/css', 'text/css');

var finished = 0; var code = [];

// all message('Loading Twinkle_global_cwlf...'); var done = function(x) { return function(data) { finished++; message('Loading Twinkle_global_cwlf... (' + finished + '/' + tests.length + ')'); code[x] = data; if (x === tests.length - 1) { localStorage.Twinkle_global_cwlf_version = VERSION; try { eval(code.join('\n;\n')); message('Twinkle Done'); } catch (e) { mw.notify('Error loading Twinkle: ' + e, {type: 'error'}); }				if ($('#twinkleglobal-config-titlebar').length) { $('#twinkleglobal-config-titlebar').append('--Version: Gomdoli4696, ' + localStorage.Twinkle_global_cwlf_version); $('#twinkleglobal-config-titlebar').append('Purge '); }			} else { load(tests[x + 1]).done(done(x + 1)); }		};	};	load(tests[0]).done(done(0)); }

mw.loader.using(['mediawiki.user', 'mediawiki.util', 'mediawiki.Title', 'jquery.ui', 'jquery.tipsy', 'mediawiki.api', 'mediawiki.ForeignApi']).done(function {	main; });

});