2019-11-23 18:41:18 -05:00
|
|
|
function identifyProtocolHandler(url) {
|
|
|
|
//console.log("looking for handler-able requests")
|
|
|
|
if (routerHost(url)) {
|
|
|
|
if (url.includes(encodeURIComponent("ext+rc:"))) {
|
|
|
|
return url.replace(encodeURIComponent("ext+rc:"), "");
|
|
|
|
} else if (url.includes("ext+rc:")) {
|
|
|
|
return url.replace("ext+rc:", "");
|
|
|
|
}
|
|
|
|
} else if (url.includes("ext+rc:")) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-23 22:17:20 -05:00
|
|
|
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];
|
|
|
|
}
|
2019-11-24 04:13:12 -05:00
|
|
|
let path = url.replace(prefix + hostname, "");
|
|
|
|
console.log("(handler) path", prefix + hostname, path);
|
|
|
|
return path;
|
2019-11-23 22:17:20 -05:00
|
|
|
}
|
|
|
|
|
2020-01-02 15:43:24 -05:00
|
|
|
var handlerSetup = function(requestDetails) {
|
2019-11-23 18:41:18 -05:00
|
|
|
//console.log("checking protocol handler listener")
|
2020-01-02 15:43:24 -05:00
|
|
|
let rwurl = identifyProtocolHandler(requestDetails.url);
|
2019-11-23 18:41:18 -05:00
|
|
|
if (rwurl != false) {
|
2019-11-23 22:17:20 -05:00
|
|
|
console.log("(handler) rewrite URL requested", rwurl);
|
2019-11-23 18:41:18 -05:00
|
|
|
requestDetails.redirectUrl = rwurl;
|
2019-11-23 22:17:20 -05:00
|
|
|
requestDetails.url = trimHost(rwurl);
|
|
|
|
requestDetails.originUrl = trimHost(rwurl);
|
2019-11-23 18:41:18 -05:00
|
|
|
}
|
|
|
|
return requestDetails;
|
|
|
|
};
|
|
|
|
|
|
|
|
browser.webRequest.onBeforeRequest.addListener(
|
|
|
|
handlerSetup,
|
2019-12-24 16:51:38 -05:00
|
|
|
{ urls: ["<all_urls>"] },
|
2019-11-23 18:41:18 -05:00
|
|
|
["blocking"]
|
|
|
|
);
|