User:逆襲的天邪鬼/NoPersonalSigns.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/*
消灭中文维基个性签名 by 逆襲的天邪鬼
用法:在[[Special:MyPage/common.js]]中加入
mw.loader.load('https://zh.wikipedia.org/w/index.php?title=User:逆襲的天邪鬼/js/NoPersonalSigns.js&action=raw&ctype=text/javascript');
如果只是想过滤个别人的签名,请在浏览器的控制台输入
localStorage.signBlackList = ['用户名', '用户名2'];
localStorage.useBlacklist = true;
我只保证自己好用,不保证别人也能看到正确的效果。
TODO:
1. 防止冤杀
2. <span>FUCK</span><span><a href="...">.....
其他:
https://en.wikipedia.org/wiki/User:Kephir/gadgets/unclutter
*/
$(function () {
var useBlacklist = localStorage.useBlacklist || false; // 若置为false则处理所有人的签名,否则只处理个别人签名。
var blacklist = localStorage.signBlackList || [];
var wgServer = mw.config.get('wgServer');
var normalizeName = function (name) {
return name.replace(/_/g, ' ');
};
// 有汰渍,没污渍
var tide = {
'carrotkit': ['SPAN'],
'1233': [undefined, 'SPAN'],
'aotfs2013': ['A'],
'tigerzeng': ['A', 'A'],
'neville wang': ['B', 'SPAN'],
'斗争和平解放人权': ['A']
};
// 奥妙全自动,去除99种污渍
var omo = {
OMO: {
'SNH48TAQ': ['🎂']
}
};
if (blacklist) {
for (var i = 0; i < blacklist.length; i++) {
blacklist[i] = normalizeName(blacklist[i]).toLowerCase();
}
}
var isIP = function (name) {
return name.match('^\\d+\\.\\d+\\.\\d+\\.\\d+$') !== null ||
name.match('^[0-9a-fA-F]+:[0-9a-fA-F:]+$') !== null;
};
var isNew = {};
var findUserName = function (node) {
if (node !== null && node.nodeType === 1) {
if (node.tagName === 'A') {
var href = node.href;
var match = href.match(wgServer + '/w(/index\\.php\\?.*?title=|iki/)(User:|User_talk:|Special:Contributions/|Special:%E7%94%A8%E6%88%B7%E8%B4%A1%E7%8C%AE/)([^/]*?)($|\\?|&|#)');
if (match && match[3]) {
var name = normalizeName(decodeURI(match[3]));
if (node.className.indexOf('new') !== -1) {
if (href.indexOf('User_talk:') !== -1) {
isNew['User talk:' + name] = true;
} else if (href.indexOf('User:') !== -1) {
isNew['User:' + name] = true;
}
}
return name;
}
} else {
var child = node.firstChild;
while (child) {
var n = findUserName(child);
if (n !== null) {
return n;
}
child = child.nextSibling;
}
}
}
return null;
};
var killSigns = function (node) {
// 确定用户名
var curNode = node.previousSibling;
var lastValidNode = null;
var username = null;
while (curNode) {
var n = findUserName(curNode);
if (n !== null) {
if (username === null) {
username = n;
}
if (n.toLowerCase() === username.toLowerCase()) {
lastValidNode = curNode;
}
}
curNode = curNode.previousSibling;
}
// 判断是否为黑名单名字
if ((useBlacklist && blacklist.indexOf(username.toLowerCase()) === -1) || lastValidNode === null) {
return;
}
if (isIP(username)) {
return;
}
// 格杀勿论
var nodes = [];
var i;
curNode = lastValidNode;
if (tide[username.toLowerCase()]) { // 使用汰渍洗衣粉强力清洗
var rubbish = tide[username.toLowerCase()];
for (var i=0; i<rubbish.length; i++) {
if (curNode.previousSibling !== null && curNode.previousSibling.tagName === rubbish[i]) {
curNode = curNode.previousSibling;
} else {
curNode = lastValidNode;
break;
}
}
}
while (curNode !== node) {
nodes.push(curNode);
curNode = curNode.nextSibling;
}
for (var i = 0; i<nodes.length; i++) {
nodes[i].remove();
}
// 换成干净的链接
var x = document.createElement('a');
var y = document.createElement('a');
x.text = username;
y.text = '留言';
x.className = 'userlink';
y.className = 'userlink';
x.href = '/wiki/User:' + username;
y.href = '/wiki/User_talk:' + username;
if (isNew['User:' + username]) {
x.className += ' new';
}
if (isNew['User talk:' + username]) {
y.className += ' new';
}
node.parentNode.insertBefore(x, node);
node.parentNode.insertBefore(document.createTextNode('('), node);
node.parentNode.insertBefore(y, node);
node.parentNode.insertBefore(document.createTextNode(')'), node);
if (node.textContent.indexOf(')') === 0) {
node.textContent = node.textContent.substr(1);
}
if (node.textContent.indexOf(')') === 0) {
node.textContent = node.textContent.substr(1);
}
// 使用奥妙全自动洗衣液,清除顽固污渍
if (omo.OMO[username]) {
var rubbish2 = omo.OMO[username];
var prev = x.previousSibling;
for (var r = 0; r<rubbish2.length; r++) {
var reg = new RegExp(rubbish2[r], 'g');
node.textContent = node.textContent.replace(reg, '');
if (prev) {
prev.textContent = prev.textContent.replace(reg, '');
}
}
}
};
var replace_text = function (node, search, callback) {
if (node.nodeType === 3)
{
value = node.nodeValue;
matches = value.match(search);
if (matches !== null) {
callback(node);
}
} else {
var children = [], child = node.firstChild;
while (child) {
children[children.length] = child;
child = child.nextSibling;
}
for (var i = 0; i < children.length; i++) {
replace_text(children[i], search, callback);
}
}
};
replace_text(document.getElementById('bodyContent'), /(\d{4})年(\d{1,2})月(\d{1,2})日 \([一二三四五六日]\) (\d\d):(\d\d) \(UTC\)/g, killSigns);
});