diff options
author | Luke Bratch <luke@bratch.co.uk> | 2017-09-18 23:08:07 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2017-09-18 23:08:07 +0100 |
commit | bc831e62fe1b286ae2342738114e55b58057631d (patch) | |
tree | 3974ff02acd51da53c862653f200722e0556395d /desktopwikipedia.js |
Initial commit
Diffstat (limited to 'desktopwikipedia.js')
-rw-r--r-- | desktopwikipedia.js | 24 |
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"] +); |