deAMP

AMP sucks, thus no AMP thanks.

Verze ze dne 19. 02. 2024. Zobrazit nejnovější verzi.

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

// ==UserScript==
// @name               deAMP
// @name:zh-TW         deAMP
// @name:zh-CN         deAMP
// @description        AMP sucks, thus no AMP thanks.
// @description:zh-TW  垃圾 AMP,好走不送。
// @description:zh-CN  垃圾 AMP,好走不送。
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            2.2.4
// @license            MIT
// @match              *://*/*
// @run-at             document-end
// @grant              GM.getValue
// @grant              GM.setValue
// @require            https://cdn.jsdelivr.net/npm/[email protected]/uuid-random.min.js
// @supportURL         https://greasyfork.org/scripts/450569/feedback
// ==/UserScript==

(async () =>
{
    const SESSION_KEY = await getSessionKey();

    const isAmp = document.documentElement.hasAttribute("⚡") || document.documentElement.hasAttribute("amp");
    const canonical = document.head.querySelector("link[rel=canonical][href]");

    if (isAmp && (canonical !== null))
    {
        const lastVisit = sessionStorage.getItem(SESSION_KEY);

        if (location.href === lastVisit)
        {
            console.debug("[deAMP] Last visited URL is the current URL, abort redirection.");
            sessionStorage.removeItem(SESSION_KEY);
        }
        else if (location.href === canonical.href)
        {
            console.debug("[deAMP] Canonical URL is the current URL, abort redirection.");
            sessionStorage.removeItem(SESSION_KEY);
        }
        else
        {
            console.debug(`[deAMP] Redirecting to canonical URL: ${canonical.href}`);

            sessionStorage.setItem(SESSION_KEY, location.href);
            location.replace(canonical.href);
        }
    }
    else
    {
        console.debug("[deAMP] Not an AMP page.");
        sessionStorage.removeItem(SESSION_KEY);
    }

    async function getSessionKey()
    {
        let key = await GM.getValue("SESSION_KEY");
        if (key) { return key; }

        key = uuid();
        GM.setValue("SESSION_KEY", key);
        return key;
    }
})();