Last active
February 25, 2022 05:21
-
-
Save a-gu/a05caf92fdaa0612724b28aba657338c to your computer and use it in GitHub Desktop.
Redirect AMP pages to their canonical counterparts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Anti-AMP | |
// @version 0.3 | |
// @description Redirect AMP pages to their canonical counterparts | |
// @author Andrew Gu | |
// @match *://*/* | |
// @grant none | |
// @run-at document-end | |
// @noframes | |
// @updateURL https://gist.github.com/a-gu/a05caf92fdaa0612724b28aba657338c/raw/anti-amp.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const ampHtml = document.querySelector('html[⚡], html[amp]'); | |
if (!ampHtml) { return; } | |
const canonical = document.head.querySelector('link[rel="canonical"]'); | |
if (!canonical || window.location.href === canonical.href) { return; } | |
window.location.href = canonical.href; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment