// ==UserScript== // @name MISC29Test // @namespace http // @description Hooks in the AMP removal javascript to attempt to direct to a proper page // @include *://*/* // @run-at document-end // @grant none // @version 1.4.1b // // // // Author: B Tasker // ==/UserScript== (function() { 'use strict'; function fuckOffAMP(){ // Check whether it's AMP html var h = document.getElementsByTagName('html'); var i = document.getElementsByTagName('iframe'); var iframenasty = false; var src; for (var a=0;a < i.length; a++){ src = i[a].getAttribute('src'); if (src.includes('cdn.ampproject.org/')){ console.log("iFrames.... Fantastic modernisation there google...."); iframenasty = true; break; } } if (iframenasty || h[0].getAttribute('amp') != null || h[0].getAttribute('âš¡') != null || document.location.href.substr(0,29).toLowerCase() == 'https://www.google.com/amp/s/'){ console.log("eww vile... trying to redirect"); // Try and find a canonical link eles = document.getElementsByTagName('link'); for (var i=0; i<eles.length;i++){ if (eles[i].getAttribute('rel') == 'canonical' && eles[i].getAttribute('rel') != window.location.href.split('#')[0]){ window.location.href = eles[i].getAttribute('href'); console.log("Redirecting you to " + eles[i].getAttribute('href')); return; } } // If we got this far, there's no canonical :( console.log("Sorry, but you're stuck with the sucky version of this page. Maybe search for the proper version?"); // Build a link to search DuckDuckGo for the page title (to hopefully find the proper version) t = document.getElementsByTagName('title')[0]; qs = encodeURIComponent(t.innerHTML); searchurl = 'https://duckduckgo.com/?t=hg&ia=web&q='+qs altlink = document.createElement('a'); altlink.href = searchurl; altlink.title = 'Try and find a proper verison of this page'; altlink.innerHTML = 'Search for a non-AMP version of this page'; // Drop the link in at the top document.body.insertBefore(altlink, document.body.firstChild); }else{ console.log("Doesn't appear to be AMP'd"); } } var b = document.getElementsByTagName('body')[0]; var s = document.createElement('script'); s.setAttribute('type','text/javascript'); s.appendChild(document.createTextNode('('+ fuckOffAMP +')();')) b.appendChild(s); })();