Greasy Fork

deAMP

AMP sucks, thus no AMP thanks.

目前为 2023-02-08 提交的版本。查看 最新版本

// ==UserScript==
// @name               deAMP
// @name:zh-TW         deAMP
// @description        AMP sucks, thus no AMP thanks.
// @description:zh-TW  垃圾 AMP,好走不送。
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.1
// @license            MIT
// @match              http*://*/*
// @run-at             document_end
// @grant              none
// @supportURL         https://greasyfork.org/scripts/450569/feedback
// ==/UserScript==

const isAmp = (document.querySelector("html[⚡], html[amp]") !== null);
const canonical = document.head.querySelector("link[rel=canonical][href]");

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

    if (location.href !== lastVisit)
    {
        sessionStorage.setItem("deAmp.lastVisit", location.href);
        location.replace(canonical.href);
    }
    else
    {
        sessionStorage.removeItem("deAmp.lastVisit");
    }
}
else
{
    console.debug("[deAMP] Not a valid AMP page.");
    sessionStorage.removeItem("deAmp.lastVisit");
}