-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbackground.js
More file actions
88 lines (84 loc) · 2.93 KB
/
background.js
File metadata and controls
88 lines (84 loc) · 2.93 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
let config = localStorage.getItem("bsp_config");
function updateTabs(message) {
browser.tabs.query({
url: [
'*://*.bingosync.com/room/*',
'*://*.bingosync.bingothon.com/room/*',
"*://*.bingo.saesr.events/room/*"
]
}).then(tabs => {
for (const tab of tabs) {
browser.tabs.sendMessage(tab.id, message);
}
});
}
function convertBlobToArrayBuffer(blob) {
return new Response(blob).arrayBuffer();
}
browser.runtime.onMessage.addListener((message, sender, respond) => {
switch (message.type) {
case "fileToClip":
// Chromium does not implement this API
// due to clipboard being manipulatable from the client.
if (!browser?.clipboard?.setImageData) {
respond({status: 'failed'});
}
respond(convertBlobToArrayBuffer(message.blob).then(arrayBuffer => {
browser.clipboard.setImageData(arrayBuffer, "png");
return true;
}).catch(error => {
console.error(error);
return false;
}));
break;
case "config":
console.log("new config");
config = message.config;
updateTabs(message);
// save to localStorage
localStorage.setItem("bsp_config", JSON.stringify(message.config));
break;
case "theme":
console.log("new theme");
updateTabs({
type: 'theme',
theme: config.theming ? message.theme : undefined
});
// save to localStorage
localStorage.setItem("bsp_theme", JSON.stringify(message.theme));
break;
case "listsA":
console.log("new lists A");
updateTabs(message);
// save to localStorage
localStorage.setItem("bsp_listsA", message.lists);
break;
case "listsB":
console.log("new lists B");
updateTabs(message);
// save to localStorage
localStorage.setItem("bsp_listsB", message.lists);
break;
case "request":
switch (message.content) {
case "config":
respond(JSON.parse(localStorage.getItem("bsp_config")));
break;
case "theme":
if (config) {
respond(config.theming ? JSON.parse(localStorage.getItem("bsp_theme")) : undefined);
}
break;
case "listsA":
respond(localStorage.getItem("bsp_listsA"));
break;
case "listsB":
respond(localStorage.getItem("bsp_listsB"));
break;
}
break;
default:
console.log("what is this message lol", message.type);
break;
}
});