summaryrefslogtreecommitdiff
path: root/desktopwikipedia.js
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2017-09-18 23:08:07 +0100
committerLuke Bratch <luke@bratch.co.uk>2017-09-18 23:08:07 +0100
commitbc831e62fe1b286ae2342738114e55b58057631d (patch)
tree3974ff02acd51da53c862653f200722e0556395d /desktopwikipedia.js
Initial commit
Diffstat (limited to 'desktopwikipedia.js')
-rw-r--r--desktopwikipedia.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/desktopwikipedia.js b/desktopwikipedia.js
new file mode 100644
index 0000000..a089d6a
--- /dev/null
+++ b/desktopwikipedia.js
@@ -0,0 +1,24 @@
+// match pattern for the URLs to redirect
+var pattern = "*://*.wikipedia.org/*";
+
+// redirect function
+// returns an object with a property `redirectURL`
+// set to the new URL
+function redirect(requestDetails) {
+ var url = new URL(requestDetails.url);
+ if (url.host.includes(".m.wikipedia.org")) {
+ url.href = url.href.replace(".m.wikipedia.org", ".wikipedia.org");
+ console.log("Redirecting: " + url.href);
+ return {
+ redirectUrl: url.href
+ };
+ }
+}
+
+// add the listener,
+// passing the filter argument and "blocking"
+browser.webRequest.onBeforeRequest.addListener (
+ redirect,
+ {urls:[pattern], types:["main_frame"]},
+ ["blocking"]
+);