autodarts_token_v5

Generiert den bearer-token

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/576340/1814186/autodarts_token_v5.js

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

(function() {
    'use strict';

    const globalScope = typeof unsafeWindow !== "undefined" ? unsafeWindow : window;

    if (globalScope.__myGlobalScriptLock) {
        return;
    }

    globalScope.__myGlobalScriptLock = GM_info.script.name;

    (function() {
        const TOKEN_ENDPOINT = "https://login.autodarts.io/realms/autodarts/protocol/openid-connect/token";

        // 1. Fetch Hook
        const originalFetch = window.fetch;
        window.fetch = function (...args) {
            const promise = originalFetch.apply(this, args);
            try {
                const url = args[0] instanceof Request ? args[0].url : String(args[0]);
                if (url.includes(TOKEN_ENDPOINT)) {
                    promise.then(res => res.clone().json().then(body => {
                        if (body.access_token) {
                            window.postMessage({ type: "AD_TOKEN_UPDATE", token: body.access_token }, "*");
                        }
                    })).catch(() => {});
                }
            } catch (e) {}
            return promise;
        };

        // 2. XHR Hook
        const orgSetHeader = XMLHttpRequest.prototype.setRequestHeader;
        XMLHttpRequest.prototype.setRequestHeader = function (name, value) {
            if (name.toLowerCase() === "authorization" && value.startsWith("Bearer ")) {
                const token = value.slice(7);

                window.postMessage({ type: "AD_TOKEN_UPDATE", token: token }, "*");

                localStorage.setItem("bearer", token);
                localStorage.setItem("bearer_ts", Date.now());
            }
            return orgSetHeader.call(this, name, value);
        };
    })();

})();