summaryrefslogtreecommitdiff
path: root/desktopwikipedia.js
blob: a089d6a9b1cbb4980713255b10021b4d15d9c323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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"]
);