Skip to content

Instantly share code, notes, and snippets.

@a-gu
Last active February 25, 2022 05:21
Show Gist options
  • Save a-gu/a05caf92fdaa0612724b28aba657338c to your computer and use it in GitHub Desktop.
Save a-gu/a05caf92fdaa0612724b28aba657338c to your computer and use it in GitHub Desktop.
Redirect AMP pages to their canonical counterparts
// ==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