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 |
Initial commit
-rw-r--r-- | desktopwikipedia.js | 24 | ||||
-rw-r--r-- | manifest.json | 21 |
2 files changed, 45 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"] +); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..e2c84f0 --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + + "author": "Luke Bratch" + + "manifest_version": 2, + "name": "Desktop Wikipedia", + "version": "0.1", + + "description": "Redirects mobile Wikipedia pages to desktop Wikipedia.", + + "background": { + "scripts": ["desktopwikipedia.js"] + }, + + "permissions": [ + "*://*.wikipedia.org/*", + "webRequest", + "webRequestBlocking" + ] + +} |