QCStats

Base library to be used in scripts for stats.quake.com

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.greatest.deepsurf.us/scripts/371849/636315/QCStats.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         QCStats
// @namespace    https://github.com/aleab/
// @version      1.0.8
// @author       aleab
// @description  Base library to be used in scripts for stats.quake.com
// @icon         https://stats.quake.com/fav/favicon-32x32.png
// @icon64       https://stats.quake.com/fav/favicon-96x96.png
// @match        https://stats.quake.com
// @match        https://stats.quake.com/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==

/* jshint esversion: 6 */
/* global $:false, localStorage:false, JSON:false */


// VARIABLES & CONSTANTS

const LS_CONFIG = "aleab_qcstats";

let listeners = {};

let abilityImages = {
    "ALL": null,
    "ANARKI": undefined,
    "ATHENA": "mod/grapple.png",
    "BJ_BLAZKOWICZ": undefined,
    "CLUTCH": "mod/laser.png",
    "DEATH_KNIGHT": "mod/flamestrike.png",
    "DOOM_SLAYER": "mod/berserk.png",
    "GALENA": "mod/totem.png",
    "KEEL": "mod/grenadeswarm.png",
    "NYX": "mod/ghostwalk.png",
    "RANGER": "mod/direorb.png",
    "SCALEBEARER": "mod/bullrush.png",
    "SLASH": "mod/plasmatrail.png",
    "SORLAG": "mod/acidspit.png",
    "STROGG": "mod/recondrone.png",
    "VISOR": undefined
};
let championAbilityDamageTypes = {
    "ALL": null,
    "ANARKI": undefined,
    "ATHENA": [ "ATHENA_HIT" ],
    "BJ_BLAZKOWICZ": undefined,
    "CLUTCH": [ "MINING_LASER" ],
    "DEATH_KNIGHT": [ "FLAME", "FLAME_DOT", "FLAME_MELEE" ],
    "DOOM_SLAYER": [ "ABILITY_BERSERK" ],
    "GALENA": [ "UNHOLY" ],
    "KEEL": [ "SWARM_GRENADE" ],
    "NYX": [ "VENDETTA_TELEFRAG" ],
    "RANGER": [ "DIRE_ORB", "DIRE_ORB_EXPLOSION", "DIRE_ORB_TELEFRAG" ],
    "SCALEBEARER": [ "SB_DASH", "SB_STOMP" ],
    "SLASH": [ "PLASMA_TRAIL", "PLASMA_TRAIL_EXPLOSION" ],
    "SORLAG": [ "ACID", "ACID_DOT", "ACID_SPIT_DIRECT" ],
    "STROGG": [ "DRONE_KAMIKAZE_EXPLOSION", "RECON_DRONE", "RECON_DRONE_EXPLOSION" ],
    "VISOR": undefined
};

// ===================

(function(history){
    let pushState = history.pushState;
    history.pushState = function(state) {
        if (typeof history.onpushstate == "function") {
            history.onpushstate({state: state});
        }
        return pushState.apply(history, arguments);
    };
})(window.history);

$(document).ready(function() {
    let aleab = {
        qcstats: {
            addPageChangedListener: function(pageRegex, f) {
                if (!(pageRegex instanceof RegExp) || typeof f !== "function") {
                    return;
                }

                if(!listeners.hasOwnProperty(pageRegex)) {
                    listeners[pageRegex] = [];
                }
                listeners[pageRegex].push(f);
            },
            loadConfig: function() {
                return JSON.parse(localStorage.getItem(LS_CONFIG)) || {};
            },
            saveConfig: function(config) {
                if (!(config instanceof Object)) { return; }
                localStorage.setItem(LS_CONFIG, JSON.stringify(config));
            },
            abilityImages: abilityImages,
            championAbilityDamageTypes: championAbilityDamageTypes
        }
    };
    window.aleab = aleab;

    window.onpopstate = history.onpushstate = async function(e) {
        // let location.href update
        await sleep(250);

        $.each(listeners, (regex, functions) => {
            if (typeof regex === "string") {
                if (regex.startsWith('/')) { regex = regex.substring(1); }
                if (regex.endsWith('/')) { regex = regex.substring(0, regex.length - 1); }
                regex = new RegExp(regex);
            }

            if (regex instanceof RegExp) {
                if (regex.test(location.href)) {
                    $.each(functions, (i, f) => f());
                }
            }
        });
    };
});

// ===================

// FUNCTIONS

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}