Ghost Trappers Wiki links on Feed

Changes the loot you find to be hyperlinks to the wiki

当前为 2017-08-18 提交的版本,查看 最新版本

// ==UserScript==
// @name         Ghost Trappers Wiki links on Feed
// @version      0.7
// @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\)|_\([0-9]+_bonus_loot\)/,'').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 if (matches[j].replace(/_\(special\)|_\([0-9]+_bonus_loot\)/,'').match(/U-boot/i) !== null) a.innerHTML = saved[j]+'<a href="http://wiki.ghost-trappers.com/index.php/'+matches[j].replace(/ /g,'_').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:_|_\([0-9]+_bonus_loot\)/,'').capitalize()+'" target="_blank">'+matches[j]+'</a>';
            while(a.firstChild) {
                document.querySelectorAll('b')[i].appendChild(a.firstChild);
            }
        }
    }
}