-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
53 lines (45 loc) · 1.09 KB
/
background.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
On startup, connect to the "ping_pong" app.
*/
console.log("startup")
var port = null
if (typeof browser != 'undefined') {
port = browser.runtime.connectNative("ipfs");
} else {
port = chrome.runtime.connectNative("ipfs")
}
console.log("got port")
var localgatewayurl = "http://localhost:8080"
/*
Listen for messages from the app.
*/
port.onMessage.addListener((response) => {
console.log("Received: " + response);
});
port.onDisconnect.addListener(() => {
console.log("ipfs disconnected");
});
//navigator.registerProtocolHandler("web+fs", "http://localhost:8080/%s", "ipfs extension")
var pattern = "https://ipfs.io/*";
function redirect(requestDetails) {
console.log("Redirecting: " + requestDetails.url);
if (requestDetails.url == "https://ipfs.io/") {
return {
redirectUrl: localgatewayurl + "/ipns/ipfs.io"
}
}
return {
redirectUrl: requestDetails.url.replace("https://ipfs.io", localgatewayurl)
};
}
var b = null
if (typeof browser != 'undefined') {
b = browser
} else {
b = chrome
}
b.webRequest.onBeforeRequest.addListener(
redirect,
{urls:[pattern]},
["blocking"]
);