gm-inject

Inject scripts into the web pages.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/494512/1373878/gm-inject.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name               gm-inject
// @description        Inject scripts into the web pages.
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.0
// @license            MIT
// ==/UserScript==

let GM_injectPageScript;
{
    let counter = 1;

    GM_injectPageScript = function GM_injectPageScript(source, args, options)
    {
        const {
            name = `injected-${counter++}`,
        } = options ?? {};

        const scriptWrapper = document.createElement("div");
        scriptWrapper.style.display = "none";

        const shadowRoot = scriptWrapper.attachShadow({ mode: "closed" });

        const script = document.createElement("script");
        script.textContent = `(${source})(${JSON.stringify(args ?? {})}); //# sourceURL=userscript://${encodeURIComponent(GM.info.script.name)}/${encodeURIComponent(name)}.js`;

        shadowRoot.append(script);
        (document.body ?? document.head ?? document.documentElement).append(scriptWrapper);
    };
}

GM.injectPageScript = GM_injectPageScript;