CORS GM

CORS via GM.xmlHttpRequest

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!)

Advertisement:

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!)

Advertisement:

// ==UserScript==
// @name         CORS GM
// @version      1.1
// @description  CORS via GM.xmlHttpRequest
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// @grant        unsafeWindow
// @connect      *
// @run-at       document-start
// @namespace https://greasyfork.org/users/1617149
// ==/UserScript==

(function () {
    'use strict';

    function gmFetch(url, options = {}) {
        return new Promise((resolve, reject) => {
            GM_xmlhttpRequest({
                method: options.method || 'GET',
                url: url,
                responseType: 'blob',
                onload: (res) => {
                    resolve(new Response(res.response, {
                        status: res.status,
                        statusText: res.statusText
                    }));
                },
                onerror: reject,
                ontimeout: reject
            });
        });
    }

    if (typeof unsafeWindow !== 'undefined') {
        unsafeWindow.fetchViaGM = gmFetch;
        unsafeWindow.CORSViaGM = { fetchViaGM: gmFetch };
    }

    window.fetchViaGM = gmFetch;
    window.CORSViaGM = { fetchViaGM: gmFetch };

    console.log('[CORS Via GM] READY');
})();