-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
52 lines (45 loc) · 1.25 KB
/
Copy pathbackground.js
File metadata and controls
52 lines (45 loc) · 1.25 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
function createImageFromUrl(url) {
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = reject;
img.src = url;
});
}
let toUpdate = new Set();
browser.runtime.onMessage.addListener(({ type }, { tab }) => {
switch (type) {
case "scrollStart":
toUpdate.add(tab.windowId);
loop(tab.windowId);
break;
case "scrollEnd":
toUpdate.delete(tab.windowId);
break;
}
});
async function loop(windowId) {
await updateTheme(windowId);
if (toUpdate.has(windowId)) {
setTimeout(async () => await loop(windowId), 10);
}
}
async function updateTheme(windowId) {
let img = await createImageFromUrl(await browser.tabs.captureVisibleTab());
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
stackBlurImage(img, canvas, 15, false, 100);
let [r, g, b] = [255,255,255]
//let [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
await browser.theme.update(windowId, {
colors: {
accentcolor: `rgb(${r},${g},${b})`,
textcolor: "black",
toolbar: "rgba(0,0,0,0.1)"
},
images: {
headerURL: canvas.toDataURL()
}
})
}
browser.tabs.onActivated.addListener((tab) => updateTheme(tab.windowId));