跳转到内容

User:Wetitpig0/有誰在啊.js:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
无编辑摘要
无编辑摘要
 
(未显示同一用户的14个中间版本)
第2行: 第2行:
* 取自[[User:Psyduck buab/現在我可以搞破壊了嗎.js]]
* 取自[[User:Psyduck buab/現在我可以搞破壊了嗎.js]]
*/
*/

(function($, mw) {
(function($, mw) {
// Create portlet link
// Create portlet link
var portletLinkOnline = mw.util.addPortletLink(
var portletLinkOnline = mw.util.addPortletLink(
'p-help',
'p-help',
'#',
'#',
'有邊個睇住呀?',
'有邊個睇住呀?',
't-spy',
't-spy',
'找行政人員',
'找行政人員',
'p',
'p',
'#n-portal'
'#n-portal'
);
);

var rcstart, rcend, time;
var users = {};
var admins = [], rollbackers = [], patrollers = [], bureaucrats = [], checkusers = [];
var api = new mw.Api();
var queue1 = [], queue2 = [];
var i = 0, k = 0;
var user;

// Bind click handler
$(portletLinkOnline).click(function(e) {
var t0 = performance.now();
e.preventDefault();

users = {};
admins = [];
rollbackers = [];
patrollers = [];
bureaucrats = [];
checkusers = [];
queue1 = [], queue2 = [];
i = 0, k = 0;

// 最近更改10分钟内的编辑用户
time = new Date();
rcstart = time.toISOString();
time.setMinutes(time.getMinutes() - 10);
rcend = time.toISOString();

//API:RecentChanges
api.get({
format: 'json',
action: 'query',
list: 'recentchanges|logevents',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500,
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[item.user] = true;
});
$.each(data.query.logevents, function(i, item) {
users[item.user] = true;
});

var filter = function(n) {
return n;
};

for (user in users) {
queue1[i] = user;
i++;
if (i === 50) {
queue1 = queue1.filter(filter);
i = queue1.length;
if (i === 50) {
queue2[k] = queue1;
queue1 = [];
i = 0;
k++;
}
}
}
if (queue1.length > 0) {
queue1 = queue1.filter(filter);
queue2[k] = queue1;
k++;
}


var rcstart, rcend, time;
var promises = [];
var users = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
var admins = [], rollbackers = [], patrollers = [], bureaucrats = [], checkusers = [];
if (user.groups) {
var api = new mw.Api();
// 找到管理员,去除adminbot
if (user.groups.indexOf('bot') === -1) {
if (user.groups.indexOf('sysop') > -1) {
admins[i] = user.name;
}
if (user.groups.indexOf('rollbacker') > -1) {
rollbackers[i] = user.name;
}
if (user.groups.indexOf('patroller') > -1) {
patrollers[i] = user.name;
}
if (user.groups.indexOf('bureaucrat') > -1) {
bureaucrats[i] = user.name;
}
if (user.groups.indexOf('checkuser') > -1) {
checkusers[i] = user.name;
}
}
}
});
};
for (var j = 0; j < k; j++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: queue2[j].join('|'),
usprop: 'groups'
}).done(mark));
}


// 查询用户权限
// Bind click handler
$(portletLinkOnline).click(function(e) {
$.when.apply($, promises).done(function() {
e.preventDefault();


admins = admins.filter(filter);
users = [];
rollbackers = rollbackers.filter(filter);
var usersExt = [];
patrollers = patrollers.filter(filter);
admins = [];
bureaucrats = bureaucrats.filter(filter);
rollbackers = [];
checkusers = checkusers.filter(filter);
patrollers = [];
bureaucrats = [];
checkusers = [];


var userlink = function(user) {
// 最近更改10分钟内的编辑用户
var p = document.createElement("p");
time = new Date();
p.innerHTML = '<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User:' + user + '" target="_blank">' + user + '</a><small style="opacity:.75;">(<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User_talk:' + user + '" target="_blank">留言</a>)</small></p>';
rcstart = time.toISOString();
return p;
time.setMinutes(time.getMinutes() - 10);
};
rcend = time.toISOString();


if (admins.length + rollbackers.length + patrollers.length + bureaucrats.length + checkusers.length > 0) {
//API:RecentChanges
var parent = document.createElement("p");
api.get({
var start = parent.appendChild(document.createElement("p"));
format: 'json',
start.appendChild(document.createTextNode("依家唔可以搞破壞,因為……"));
action: 'query',
list: 'recentchanges|logevents',
rcprop: 'user',
rcstart: rcstart,
rcend: rcend,
rcshow: '!bot|!anon',
rclimit: 500,
leprop: 'user',
lestart: rcstart,
leend: rcend,
lelimit: 500
}).done(function(data) {
$.each(data.query.recentchanges, function(i, item) {
users[i] = item.user;
});
var j = users.length;
$.each(data.query.logevents, function(i, item) {
users[j + i] = item.user;
});
// 使用者名稱去重與分割
users = $.unique(users.sort());
var promises = [];
var mark = function(data) {
$.each(data.query.users, function(i, user) {
// 找到管理员,去除adminbot
if ($.inArray('bot', user.groups) === -1) {
if ($.inArray('sysop', user.groups) > -1) {
admins[i] = user.name;
}
if ($.inArray('rollbacker', user.groups) > -1) {
rollbackers[i] = user.name;
}
if ($.inArray('patroller', user.groups) > -1) {
patrollers[i] = user.name;
}
if ($.inArray('bureaucrat', user.groups) > -1) {
bureaucrats[i] = user.name;
}
if ($.inArray('checkuser', user.groups) > -1) {
checkusers[i] = user.name;
}
}
});
};
for (var i=0; i<(users.length+50)/50; i++) {
promises.push(api.get({
format: 'json',
action: 'query',
list: 'users',
ususers: users.slice(i*50, (i+1)*50).join('|'),
usprop: 'groups'
}).done(mark));
}


if (admins.length > 0) {
// 查询用户权限
var adminp = document.createElement("p");
$.when.apply($, promises).done(function () {
adminp.style = "word-break:break-all;";
// 消除空值
adminp.innerHTML = "有" + admins.length + "個管理員望住你,問你死未:";
var filter = function(n) {
$.each(admins, function(i, e) {
return n;
adminp.appendChild(userlink(e));
};
});
parent.appendChild(adminp);
admins = admins.filter(filter);
}
rollbackers = rollbackers.filter(filter);
patrollers = patrollers.filter(filter);
bureaucrats = bureaucrats.filter(filter);
checkusers = checkusers.filter(filter);


if (patrollers.length > 0) {
var userlink = function(user) {
var p = document.createElement("p");
var patrolp = document.createElement("p");
patrolp.style = "word-break:break-all;";
p.innerHTML = '<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User:' + user + '" target="_blank">' + user + '</a><small style="opacity:.75;">(<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User_talk:' + user + '" target="_blank">留言</a>)</small></p>';
patrolp.innerHTML = "有" + patrollers.length + "個巡查員等緊你,問你死未:";
return p;
$.each(patrollers, function(i, e) {
};
patrolp.appendChild(userlink(e));
});
if (admins.length + rollbackers.length + patrollers.length + bureaucrats.length + checkusers.length > 0) {
parent.appendChild(patrolp);
var parent = document.createElement("p");
}
var start = parent.appendChild(document.createElement("p"));
start.appendChild(document.createTextNode("依家唔可以搞破壞,因為……"));


if (admins.length > 0) {
if (rollbackers.length > 0) {
var adminp = document.createElement("p");
var rollbackp = document.createElement("p");
adminp.style = "word-break:break-all;";
rollbackp.style = "word-break:break-all;";
adminp.innerHTML = "有" + admins.length + "個管理望住你,問你死未:";
rollbackp.innerHTML = "有" + rollbackers.length + "個回退準備捉立功,問你死未:";
$.each(admins, function(i, e) {
$.each(rollbackers, function(i, e) {
adminp.appendChild(userlink(e));
rollbackp.appendChild(userlink(e));
});
});
parent.appendChild(adminp);
parent.appendChild(rollbackp);
}
}


if (patrollers.length > 0) {
if (bureaucrats.length > 0) {
var patrolp = document.createElement("p");
var bureaup = document.createElement("p");
patrolp.style = "word-break:break-all;";
bureaup.style = "word-break:break-all;";
patrolp.innerHTML = "有" + patrollers.length + "個巡查等緊你,問你死未:";
bureaup.innerHTML = "有" + bureaucrats.length + "個行政盯實你,問你死未:";
$.each(patrollers, function(i, e) {
$.each(bureaucrats, function(i, e) {
patrolp.appendChild(userlink(e));
bureaup.appendChild(userlink(e));
});
});
parent.appendChild(patrolp);
parent.appendChild(bureaup);
}
}


if (rollbackers.length > 0) {
if (checkusers.length > 0) {
var rollbackp = document.createElement("p");
var checkp = document.createElement("p");
rollbackp.style = "word-break:break-all;";
checkp.style = "word-break:break-all;";
rollbackp.innerHTML = "有" + rollbackers.length + "個回退準備捉立功,問你死未:";
checkp.innerHTML = "有" + checkusers.length + "個用戶查核想查你,問你死未:";
$.each(rollbackers, function(i, e) {
$.each(checkusers, function(i, e) {
rollbackp.appendChild(userlink(e));
checkp.appendChild(userlink(e));
});
});
parent.appendChild(rollbackp);
parent.appendChild(checkp);
}
}
if (bureaucrats.length > 0) {
var bureaup = document.createElement("p");
bureaup.style = "word-break:break-all;";
bureaup.innerHTML = "有" + bureaucrats.length + "個行政員盯實你,問你死未:";
$.each(bureaucrats, function(i, e) {
bureaup.appendChild(userlink(e));
});
parent.appendChild(bureaup);
}
if (checkusers.length > 0) {
var checkp = document.createElement("p");
checkp.style = "word-break:break-all;";
checkp.innerHTML = "有" + checkusers.length + "個用戶查核員想查你,問你死未:";
$.each(checkusers, function(i, e) {
checkp.appendChild(userlink(e));
});
parent.appendChild(checkp);
}


mw.notify(parent);
mw.notify(parent);
} else {
} else {
mw.notify('現在沒有管理人員在線,可以去搞破壞啦,快少少啦!');
mw.notify('現在沒有管理人員在線,可以去搞破壞啦,快少少啦!');
}
}
}).fail(function () {
}).fail(function() {
mw.notify('查詢失敗');
mw.notify('查詢失敗');
});
});
});
});
console.log(performance.now() - t0);
});
});
})(jQuery, mw);
})(jQuery, mw);

2018年11月5日 (一) 10:09的最新版本

/**
 * 取自[[User:Psyduck buab/現在我可以搞破壊了嗎.js]]
 */
(function($, mw) {
	// Create portlet link
	var portletLinkOnline = mw.util.addPortletLink(
		'p-help',
		'#',
		'有邊個睇住呀?',
		't-spy',
		'找行政人員',
		'p',
		'#n-portal'
	);

	var rcstart, rcend, time;
	var users = {};
	var admins = [], rollbackers = [], patrollers = [], bureaucrats = [], checkusers = [];
	var api = new mw.Api();
	var queue1 = [], queue2 = [];
	var i = 0, k = 0;
	var user;

	// Bind click handler
	$(portletLinkOnline).click(function(e) {
		var t0 = performance.now();
		e.preventDefault();

		users = {};
		admins = [];
		rollbackers = [];
		patrollers = [];
		bureaucrats = [];
		checkusers = [];
		queue1 = [], queue2 = [];
		i = 0, k = 0;

		// 最近更改10分钟内的编辑用户
		time = new Date();
		rcstart = time.toISOString();
		time.setMinutes(time.getMinutes() - 10);
		rcend = time.toISOString();

		//API:RecentChanges
		api.get({
			format: 'json',
			action: 'query',
			list: 'recentchanges|logevents',
			rcprop: 'user',
			rcstart: rcstart,
			rcend: rcend,
			rcshow: '!bot|!anon',
			rclimit: 500,
			leprop: 'user',
			lestart: rcstart,
			leend: rcend,
			lelimit: 500
		}).done(function(data) {
			$.each(data.query.recentchanges, function(i, item) {
				users[item.user] = true;
			});
			$.each(data.query.logevents, function(i, item) {
				users[item.user] = true;
			});

			var filter = function(n) {
				return n;
			};

			for (user in users) {
				queue1[i] = user;
				i++;
				if (i === 50) {
					queue1 = queue1.filter(filter);
					i = queue1.length;
					if (i === 50) {
						queue2[k] = queue1;
						queue1 = [];
						i = 0;
						k++;
					}
				}
			}
			if (queue1.length > 0) {
				queue1 = queue1.filter(filter);
				queue2[k] = queue1;
				k++;
			}

			var promises = [];
			var mark = function(data) {
				$.each(data.query.users, function(i, user) {
					if (user.groups) {
						// 找到管理员,去除adminbot
						if (user.groups.indexOf('bot') === -1) {
							if (user.groups.indexOf('sysop') > -1) {
								admins[i] = user.name;
							}
							if (user.groups.indexOf('rollbacker') > -1) {
								rollbackers[i] = user.name;
							}
							if (user.groups.indexOf('patroller') > -1) {
								patrollers[i] = user.name;
							}
							if (user.groups.indexOf('bureaucrat') > -1) {
								bureaucrats[i] = user.name;
							}
							if (user.groups.indexOf('checkuser') > -1) {
								checkusers[i] = user.name;
							}
						}
					}
				});
			};
			for (var j = 0; j < k; j++) {
				promises.push(api.get({
					format: 'json',
					action: 'query',
					list: 'users',
					ususers: queue2[j].join('|'),
					usprop: 'groups'
				}).done(mark));
			}

			// 查询用户权限
			$.when.apply($, promises).done(function() {

				admins = admins.filter(filter);
				rollbackers = rollbackers.filter(filter);
				patrollers = patrollers.filter(filter);
				bureaucrats = bureaucrats.filter(filter);
				checkusers = checkusers.filter(filter);

				var userlink = function(user) {
					var p = document.createElement("p");
					p.innerHTML = '<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User:' + user + '" target="_blank">' + user + '</a><small style="opacity:.75;">(<a href="http://zh.wikipedia.org/zhwiki/w/index.php?title=User_talk:' + user + '" target="_blank">留言</a>)</small></p>';
					return p;
				};

				if (admins.length + rollbackers.length + patrollers.length + bureaucrats.length + checkusers.length > 0) {
					var parent = document.createElement("p");
					var start = parent.appendChild(document.createElement("p"));
					start.appendChild(document.createTextNode("依家唔可以搞破壞,因為……"));

					if (admins.length > 0) {
						var adminp = document.createElement("p");
						adminp.style = "word-break:break-all;";
						adminp.innerHTML = "有" + admins.length + "個管理員望住你,問你死未:";
						$.each(admins, function(i, e) {
							adminp.appendChild(userlink(e));
						});
						parent.appendChild(adminp);
					}

					if (patrollers.length > 0) {
						var patrolp = document.createElement("p");
						patrolp.style = "word-break:break-all;";
						patrolp.innerHTML = "有" + patrollers.length + "個巡查員等緊你,問你死未:";
						$.each(patrollers, function(i, e) {
							patrolp.appendChild(userlink(e));
						});
						parent.appendChild(patrolp);
					}

					if (rollbackers.length > 0) {
						var rollbackp = document.createElement("p");
						rollbackp.style = "word-break:break-all;";
						rollbackp.innerHTML = "有" + rollbackers.length + "個回退員準備捉你立功,問你死未:";
						$.each(rollbackers, function(i, e) {
							rollbackp.appendChild(userlink(e));
						});
						parent.appendChild(rollbackp);
					}

					if (bureaucrats.length > 0) {
						var bureaup = document.createElement("p");
						bureaup.style = "word-break:break-all;";
						bureaup.innerHTML = "有" + bureaucrats.length + "個行政員盯實你,問你死未:";
						$.each(bureaucrats, function(i, e) {
							bureaup.appendChild(userlink(e));
						});
						parent.appendChild(bureaup);
					}

					if (checkusers.length > 0) {
						var checkp = document.createElement("p");
						checkp.style = "word-break:break-all;";
						checkp.innerHTML = "有" + checkusers.length + "個用戶查核員想查你,問你死未:";
						$.each(checkusers, function(i, e) {
							checkp.appendChild(userlink(e));
						});
						parent.appendChild(checkp);
					}

					mw.notify(parent);
				} else {
					mw.notify('現在沒有管理人員在線,可以去搞破壞啦,快少少啦!');
				}
			}).fail(function() {
				mw.notify('查詢失敗');
			});
		});
		console.log(performance.now() - t0);
	});
})(jQuery, mw);