-
Notifications
You must be signed in to change notification settings - Fork 0
/
foreground.js
58 lines (54 loc) · 2 KB
/
foreground.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
54
55
56
57
58
if (!document.novioWalletConnected) {
document.addEventListener('onNovioTxRequest', novioTxRequestEventHandler);
function novioTxRequestEventHandler(event) {
chrome.runtime.sendMessage({
message: "onNovioTxRequest",
data: event.detail,
}, (response) => {
const txResponseEvent = new CustomEvent("onNovioTxResponse", {
bubbles: true,
cancelable: false,
detail: {
type: event.detail.type,
data: response,
},
});
document.dispatchEvent(txResponseEvent);
});
}
document.addEventListener('onNovioSignRequest', novioSignRequestEventHandler);
function novioSignRequestEventHandler(event) {
chrome.runtime.sendMessage({
message: "onNovioSignRequest",
data: event.detail.data,
}, (response) => {
const signResponseEvent = new CustomEvent("onNovioSignResponse", {
bubbles: true,
cancelable: false,
detail: {
type: event.detail.type,
data: response,
},
});
document.dispatchEvent(signResponseEvent);
});
}
const onNovioConnectedEvent = new CustomEvent("onNovioConnected", {
"bubbles": true,
"cancelable": false,
"detail": {},
});
document.dispatchEvent(onNovioConnectedEvent);
var port = chrome.runtime.connect({ name: "novio-contentScript" });
port.onDisconnect.addListener(function () {
document.removeEventListener('onNovioTxRequest', novioTxRequestEventHandler);
document.novioWalletConnected = false;
const onNovioDisconnectedEvent = new CustomEvent("onNovioDisconnected", {
"bubbles": true,
"cancelable": false,
"detail": {},
});
document.dispatchEvent(onNovioDisconnectedEvent);
});
}
document.novioWalletConnected = true;