Ghost Trappers Wiki links on Feed

Adds wiki links to your feed for loot and ghosts

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Ghost Trappers Wiki links on Feed
// @version      1.2
// @description  Adds wiki links to your feed for loot and ghosts
// @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==


//Seperates regex into array
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;
}

//Capitlizes the first letter and lower cases the rest
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
};


//Loot conversion to Links
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');
            //First match for Contracts
            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>';
            //Second match for U-boot mocktail
            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>';
            //Third for the rest
            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);
            }
        }
    }
}

//Adds link to ghosts wiki page when clicking on picture in feed
for (i = 0; i < document.querySelectorAll('div[class*=logText]').length; i++) {
    if (document.querySelectorAll('div[class*=logText]')[i].innerText.match(/You helped your fellow agent/) !== null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/Livefeed_and_assist_loot" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
    else if (document.querySelectorAll('div[class*=logText]')[i].innerText.match(/You encountered (?:a|an) .*, but it/) !== null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/' + document.querySelectorAll('div[class*=logText]')[i].innerText.match(/You encountered (?:a|an) (.*), but it/)[1].replace(/ /g,'_') + '" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
    else if (document.querySelectorAll('div[class*=logText]')[i].innerText.match(/You fall through a trap door into|You left the trap door and are back in/) !== null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/Trapdoor" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
    else if (document.querySelectorAll('div[class*=logText]')[i].children[2].innerText.match(/ghost monster journal/) !== null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/' + document.querySelectorAll('div[class*=logText]')[i].innerText.match(/You encountered (?:a|an) (.*). This/)[1].replace(/ /g,'_') + '" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
    else if (document.querySelectorAll('div[class*=logText]')[i].children[2].innerText.match(/frozen|burning/) !== null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/' + document.querySelectorAll('div[class*=logText]')[i].innerText.match(/(?:You encountered|have successfully trapped) (?:a|an) (?:frozen|burning) (.*)(?:, but|\. The)/)[1].replace(/ /g,'_') + '" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
    else if (document.querySelectorAll('div[class*=logText]')[i].children[2].innerText.match(/frozen|burning|ghost monster journal/) === null) {
        document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML = '<a href="http://wiki.ghost-trappers.com/index.php/' + document.querySelectorAll('div[class*=logText]')[i].children[2].innerText.replace(/ /g,'_') + '" target="_blank" >' + document.querySelectorAll('div[class*=logImageOverlay]')[i].outerHTML + '</a>';
    }
}