-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadTwinkle.js
96 lines (84 loc) · 3.58 KB
/
LoadTwinkle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* eslint-disable no-console */
/**
* +-------------------------------------------------------------------------+
* | === 警告 === |
* | 本工具有一些新穎的修改,雖本人會經過測試,但不能保證不會出錯 |
* | 強烈建議在使用後複查編輯,特別是那些新功能 |
* | 詳情請見[[User:Xiplus/Twinkle]] |
* +-------------------------------------------------------------------------+
*/
// 複製並修改自 https://zh.wikipedia.org/w/index.php?oldid=45972864 作者為 User:逆襲的天邪鬼
// 載入自己修改的Twinkle
(function() {
var VERSION = '{{subst:#time:Y-m-d H:i:s}}';
var PREFIX = 'User:Xiplus/Twinkle/';
var rebuildcache = localStorage.A64Twinkle_version !== VERSION;
var tests = [];
var ajax = function(title) {
return $.ajax({
url: 'https://zh-classical.wikipedia.org/w/index.php?title=' + title + '&action=raw&ctype=text/javascript',
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]);
}
if (p.test) {
return ajax(PREFIX + p.name).done(done);
}
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/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/twinkleclose.js', test: true });
tests.push({ name: 'modules/twinkleconfig.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/twinklespeedy.js', test: true });
tests.push({ name: 'modules/twinkleunlink.js', test: true });
tests.push({ name: 'modules/twinklewarn.js', test: true });
tests.push({ name: 'modules/twinklexfd.js', test: true });
mw.loader.using(['mediawiki.user', 'mediawiki.util', 'mediawiki.Title', 'jquery.ui', 'jquery.tipsy', 'jquery.chosen']).done(function() {
mw.loader.load('https://zh-classical.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');
if ($('#twinkle-config-titlebar').length) {
$('#twinkle-config-titlebar').append('--版本:Xiplus ' + localStorage.A64Twinkle_version);
$('#twinkle-config-titlebar').append('<button onclick="localStorage.A64Twinkle_version = \'\';location.reload();">清除快取</button>');
}
});
});
})();