Changes the loot you find to be hyperlinks to the wiki
当前为
// ==UserScript==
// @name Ghost Trappers Wiki links on Feed
// @version 0.5
// @description Changes the loot you find to be hyperlinks to the wiki
// @author Hazado
// @match *www.ghost-trappers.com/fb/camp.php*
// @match *www.ghost-trappers.com/fb/hunt.php*
// @grant none
// @namespace https://greasyfork.org/users/149039
// ==/UserScript==
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};
for (i = 0; i < document.querySelectorAll('b').length; i++) {
if (document.querySelectorAll('b')[i].innerHTML.search('^<br>[0-9]+') === 0)
{
var matches = getMatches(document.querySelectorAll('b')[i].innerHTML,/<br>[0-9]+(?: x)? ([a-zA-Z -:()]*)/g,0);
var saved = getMatches(document.querySelectorAll('b')[i].innerHTML,/(<br>[0-9]+(?: x)? )[a-zA-Z -:()]*/g,0);
document.querySelectorAll('b')[i].innerHTML = null;
for (j = 0; j < matches.length; j++) {
var a = document.createElement('a');
if (matches[j].replace(/_\(special\)/,'').match(/[A_Z]*\.[0-9]/) !== null) a.innerHTML = saved[j]+'<a href="http://wiki.ghost-trappers.com/index.php/'+matches[j].replace(/ /g,'_').replace(/_-_/,'_').replace(/-/,'/').replace(/Blueprint:_|_\(special\)|Molding_half:_|Schematic:_/,'')+'" target="_blank">'+matches[j]+'</a>';
else a.innerHTML = saved[j]+'<a href="http://wiki.ghost-trappers.com/index.php/'+matches[j].replace(/ /g,'_').replace(/_-_/,'_').replace(/-/,'/').replace(/Blueprint:_|_\(special\)|Molding_half:_|Schematic:_/,'').capitalize()+'" target="_blank">'+matches[j]+'</a>';
while(a.firstChild) {
document.querySelectorAll('b')[i].appendChild(a.firstChild);
}
}
}
}