User:Wcam/123chalinker.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// ==UserScript==
// @name Wiki 123cha linker
// @author Arendedwinter
// @namespace (none)
// @include *.wikipedia.org/*
// @description Creates a link next to each anon IP for easy 123cha searches. Should work on all language Wikis
// adapted by User:Wcam
// ==/UserScript==
//SET SOME VARIABLES
var Link = document.getElementsByTagName('a');
var IPFilter = /^.*([0-9]{0,2})+\.([0-9]{0,2})+\.([0-9]{0,2})+\.([0-9]{0,2})+$/;
var ExtraLinkURL = 'http://www.123cha.com/ip/?q=';
var ExtraLinkTarget = '_blank';
var ExtraLinkTitle = 'WHOIS this IP';
var ExtraLinkText = ' <font size="1"><font color="black">(</font><u><font color="#CC0000">123cha</font></u><font color="black">)</font></font>';
//DO STUFF!
//Yes I'm aware this can be written better...
$(function() {
for (var i = 0; i < Link.length; i++){
//Filter out external links (eg: Enzyme Commission codes are the same format as an IP)
// var InWikipedia = /wikipedia/.test(Link[i].href);
// var InWikipedia = true;
// if (InWikipedia == true){
if (Link[i].textContent.match(IPFilter)){
ExtraLinkSpan = document.createElement('span');
if (Link[i].textContent.match(/\:/g)){
var NewLink = Link[i].textContent.split(/\:/g);
NewLink = NewLink[1];
if (NewLink.match(/\//g)){
var NewLink = Link[i].textContent.split(/\//g);
NewLink = NewLink[1];
}
}else{
var NewLink = Link[i].textContent;
}
ExtraLink = '<a href="' + ExtraLinkURL + NewLink + '" target="' + ExtraLinkTarget + '" title="' + ExtraLinkTitle + '">' + ExtraLinkText + '</a>';
ExtraLinkSpan.innerHTML = ExtraLink;
Link[i].parentNode.insertBefore(ExtraLinkSpan, Link[i].nextSibling);
}
// }
}
});