deAMP

AMP sucks, thus no AMP thanks.

当前为 2023-02-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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            2.0.1
// @license            MIT
// @match              http*://*/*
// @run-at             document_end
// @grant              GM_getValue
// @grant              GM_setValue
// @supportURL         https://greasyfork.org/scripts/450569/feedback
// ==/UserScript==

const SESSION_KEY = getSessionKey();

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(SESSION_KEY);

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

    sessionStorage.removeItem(SESSION_KEY);
}


function getSessionKey()
{
    const SESSION_KEY = "sessionKey";

    let key = GM_getValue(SESSION_KEY);
    if (!key)
    {
        key = generateUuidV4();
        GM_setValue(SESSION_KEY, key);
    }

    return key;


    function generateUuidV4()
    {
        const uuid = new Array(36);
        for (let i = 0; i < 36; i++) { uuid[i] = Math.floor(Math.random() * 16); }
        uuid[14] = 4;
        uuid[19] = uuid[19] &= ~(1 << 2);
        uuid[19] = uuid[19] |= (1 << 3);
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
        return uuid.map((x) => x.toString(16)).join("");
    }
}