Astral WCL Personal Log Decoration

Add Astral recruitment decoration to WCL pages

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Astral WCL Personal Log Decoration
// @namespace    https://www.warcraftlogs.com/
// @version      0.03
// @description  Add Astral recruitment decoration to WCL pages
// @author       Pewbies / Faignz
// @match        https://www.warcraftlogs.com/character/*/*/*
// @match        https://www.warcraftlogs.com/character/id/*
// @icon         https://www.astralguild.com/styles/astral/xenforo/xenforo-logo.png
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    addAstralButton();

    const buildListOfLinks = ( wclId ) => {
        return [
            { 'service': 'WoW Analyzer', 'image': 'https://wowanalyzer.com/favicon.ico', 'url': `https://wowanalyzer.com/report/${ wclId }` },
            { 'service': 'Warcraft Logs', 'image': 'https://www.wipefest.gg/favicon.ico', 'url': `https://www.wipefest.gg/report/${ wclId }?gameVersion=warcraft-live` },
        ]
    }

    window.startProcessing = function( status ) {
        if ( status ) { addAstralLinks(); }
        else { alertUser( 'Please select a boss fight then click this button again.' ); }
    }

    function addAstralLinks() {
        Array.from( document.getElementById('boss-table').children[0].children )[0].insertCell().innerHTML = `<img src='https://www.astralguild.com/styles/astral/xenforo/xenforo-logo.png' style='height: 20px; display: block; margin-left: auto; margin-right: auto;'>`;
        Array.from( document.getElementById('boss-table').children[1].children ).forEach( row => {
            const wclogUrl = row.getElementsByClassName('rank-per-second')[0].children[0].href;
            const wclId = wclogUrl.split('/').pop().split('#')[0];
            const linkObj = buildListOfLinks(wclId);
            const displayHtml = linkObj.reduce( (acc, curr) => {
                acc += `<a href = '${ curr.url }' target='_blank'> <img src='${ curr.image }'/> </a>&nbsp;&nbsp`;
                return acc;
            }, '')
            row.insertCell().innerHTML += displayHtml;
        })
    }

    function addAstralButton() {
        const div = document.createElement('div');
        div.innerHTML = ( `<button class='addAstralLinks' style='position: fixed; top: 0; right: 0; z-index: 99999; height: 30px; background-repeat: no-repeat; background-size: contain; width: 100px; background-color: #111826; background-image:url("https://www.astralguild.com/styles/astral/xenforo/xenforo-logo.png")' onclick='startProcessing(checkForCorrectTable())'/></button>`);
        document.body.prepend(div);
    }

    window.checkForCorrectTable = function() { return document.getElementById('boss-table') || false; }

    function alertUser( message ) { alert(message); }
})();