Last active
April 10, 2020 22:43
-
-
Save Ultrabenosaurus/b94d373f3a32d2b5d6ae5256e04784a7 to your computer and use it in GitHub Desktop.
Proof-of-Concept Firefox Add-On to Redirect Before Page Loads
This file contains 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
{ | |
"description": "Redirect AMP addresses to their non-AMP sources", | |
"manifest_version": 2, | |
"name": "AMP Redirect", | |
"version": "0.1", | |
"author": "Ultrabenosaurus", | |
"_comments_": { | |
"signed_xpi": "https://drive.google.com/file/d/1Pg19uXregtxfENnKO3tcvR2SiTu01IYf/view?usp=sharing", | |
"source:": "https://gist.github.com/Ultrabenosaurus/b94d373f3a32d2b5d6ae5256e04784a7", | |
"based_on": "https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRequest", | |
"userscript": "https://greasyfork.org/en/scripts/400161-amp-redirect" | |
}, | |
"permissions": [ | |
"webRequest", | |
"webRequestBlocking", | |
"<all_urls>" | |
], | |
"background": { | |
"scripts": ["redirect.js"] | |
} | |
} |
This file contains 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
/** | |
* | |
* name AMP Redirect | |
* namespace ultrabenosaurus.AMP | |
* version 0.1 | |
* description Redirect AMP addresses to their non-AMP sources | |
* author Ultrabenosaurus | |
* signed XPI https://drive.google.com/file/d/1Pg19uXregtxfENnKO3tcvR2SiTu01IYf/view?usp=sharing | |
* source https://gist.github.com/Ultrabenosaurus/b94d373f3a32d2b5d6ae5256e04784a7 | |
* userscript https://greasyfork.org/en/scripts/400161-amp-redirect | |
* | |
* Based on MDN web docs: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onBeforeRequest | |
* | |
* from: https://www-techradar-com.cdn.ampproject.org/v/s/www.techradar.com/amp/news/eliminating-vpns-for-more-secure-productive-remote-work?amp_js_v=a3&_gsa=1&usqp=mq331AQFKAGwASA%3D#referrer=https%3A%2F%2Fwww.google.com&_tf=From%20%251%24s | |
* to: https://www.techradar.com/news/eliminating-vpns-for-more-secure-productive-remote-work | |
* | |
*/ | |
function UBredirect(requestDetails){ | |
// console.log(requestDetails); | |
var a = requestDetails.url.split("/"); | |
// console.log(a); | |
var al = a.length; | |
var d = a[2].split(".")[0].replace(/-/g,"."); | |
// console.log(d); | |
if(d == a[5]){ | |
var p = a[al-1].split("?")[0]; | |
for (var i = al-2; i > 6; i--) { | |
if(a[i] !== "amp") { p = a[i]+"/"+p; } | |
// console.log(a[i]); | |
} | |
// console.log(p); | |
var s = a[0]+"//"+d+"/"+p; | |
// console.log(s); | |
return { | |
redirectUrl: s | |
}; | |
} | |
} | |
browser.webRequest.onBeforeRequest.addListener( | |
UBredirect, | |
{urls: ["<all_urls>"]}, | |
["blocking"] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www-techradar-com.cdn.ampproject.org/v/s/www.techradar.com/amp/news/eliminating-...
?These are supported:
You should probably report few samples to the author - maybe he will add them.
Hmmm, seems you have network issues. Works for me on two different browsers and two devices.