User:逆襲的天邪鬼/NoPersonalSigns.js

/*  消灭个性签名

by 逆襲的天邪鬼

TODO: 1. 该红链时红链 2. 防止冤杀 */

$(function {    var useBlacklist = false;       // 若置为false则处理所有人的签名，否则只处理个别人签名.

var blacklist = [ '用户名' ];

// 如果能把名单存到localStorage那么最好 if (localStorage.signBlackList) { blacklist = localStorage.signBlackList; }

var normalizeName = function (name) { return name.replace(/_/g, ' '); };

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 findUserName = function (node) { if (node !== null && node.nodeType === 1) { if (node.tagName === 'A') { var href = node.href; var match = href.match('(title=|/)(User:|User_talk:|Special:Contributions\\/|Special:%E7%94%A8%E6%88%B7%E8%B4%A1%E7%8C%AE\\/)(.*?)($|&|#|\\/)'); if (match && match[3]) { return normalizeName(decodeURI(match[3])); }           } else { var child = node.firstChild; while (child) { var n = findUserName(child); if (n !== null) { return n;                   } child = child.nextSibling; }

}       }        return null; };

var FUCK = 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 fuckers = []; curNode = lastValidNode; while (curNode !== node) { fuckers.push(curNode); curNode = curNode.nextSibling; }       for (var i = 0; i<fuckers.length; i++) { fuckers[i].remove; }

// 换成干净的链接 var x = document.createElement('a'); var y = document.createElement('a');

x.text = username; y.text = '留言'; x.herf = '/wiki/User:' + username; y.href = '/wiki/User_talk:' + username;

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);        }    };

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, FUCK); });