mirror of
https://github.com/SimonBrazell/privacy-redirect
synced 2025-01-06 21:42:04 +01:00
better GET processing
This commit is contained in:
parent
010d19aff9
commit
9d92671692
@ -543,24 +543,41 @@ function redirectGoogleTranslate(url, initiator) {
|
||||
}
|
||||
|
||||
function redirectWikipedia(url, initiator) {
|
||||
console.log(url);
|
||||
if (disableWikipedia || isException(url, initiator)) {
|
||||
return null;
|
||||
}
|
||||
let GETArguments = [];
|
||||
if (url.search.length > 0) {
|
||||
let search = url.search.substring(1); //get rid of '?'
|
||||
let argstrings = search.split('&');
|
||||
for (let i = 0; i < argstrings.length;i++) {
|
||||
let args = argstrings[i].split('=');
|
||||
GETArguments.push([args[0],args[1]]);
|
||||
}
|
||||
}
|
||||
|
||||
let link = `${wikipediaInstance}${url.pathname}`;
|
||||
let urlSplit = url.host.split('.');
|
||||
if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") {
|
||||
if (urlSplit[0] == 'm')
|
||||
link += "?mobileaction=toggle_view_mobile";
|
||||
GETArguments.push(["mobileaction","toggle_view_mobile"]);
|
||||
else
|
||||
link += `?lang=${urlSplit[0]}`;
|
||||
GETArguments.push(["lang",urlSplit[0]]);
|
||||
if (urlSplit[1] == 'm')
|
||||
link += "&mobileaction=toggle_view_mobile";
|
||||
GETArguments.push(["mobileaction","toggle_view_mobile"]);
|
||||
//wikiless doesn't have mobile view support yet
|
||||
}
|
||||
for (let i = 0; i < GETArguments.length; i++) {
|
||||
link += (i == 0 ? '?' : '&') + GETArguments[i][0] +
|
||||
'=' + GETArguments[i][1];
|
||||
}
|
||||
if (urlSplit[urlSplit.length - 1] == "org" &&
|
||||
urlSplit[urlSplit.length - 2] == "wikipedia")
|
||||
urlSplit[urlSplit.length - 2] == "wikipedia")
|
||||
//just in case someone wanted to visit wikipedia.org.foo.bar.net
|
||||
return link;
|
||||
return link;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
browser.webRequest.onBeforeRequest.addListener(
|
||||
|
Loading…
Reference in New Issue
Block a user