-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathhandler.js
30 lines (29 loc) · 852 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function trimHost(url) {
let hostname = "";
let prefix = "";
if (url.indexOf("://") > -1) {
prefix = url.substr(0, url.indexOf("://") + 3);
hostname = url.split("/")[2];
} else {
hostname = url.split("/")[0];
}
let path = url.replace(prefix + hostname, "");
console.log("(handler) path", prefix + hostname, path);
return path;
}
function handlerSetup(requestDetails) {
//console.log("checking protocol handler listener")
let rwurl = identifyProtocolHandler(requestDetails.url);
if (rwurl != false) {
console.log("(handler) rewrite URL requested", rwurl);
requestDetails.redirectUrl = rwurl;
requestDetails.url = trimHost(rwurl);
requestDetails.originUrl = trimHost(rwurl);
}
return requestDetails;
}
/*
browser.webRequest.onBeforeRequest.addListener(handlerSetup, {
urls: ['<all_urls>'],
});
*/