-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.ts
48 lines (42 loc) · 915 Bytes
/
version.ts
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
import { nanoid } from "nanoid";
declare const browser: any;
const ext = chrome ?? browser;
const extId = ext.runtime.id;
const version = process.env.VERSION;
const salt = nanoid();
window.addEventListener(
"message",
(evt) => {
if (
evt.source === window &&
evt.origin === location.origin &&
evt.data?.salt === salt
) {
switch (evt.data.type) {
case "wigwam.reply":
ext.runtime.sendMessage({
type: "__APPLY_WEBSITE_DATA",
data: evt.data.data,
});
break;
case "wigwam.openapp":
ext.runtime.sendMessage({ type: "__OPEN_OR_FOCUS_TAB" });
break;
default:
break;
}
}
},
false,
);
window.addEventListener("load", () => {
window.postMessage(
{
type: "wigwam.version",
extId,
version,
salt,
},
location.origin,
);
});