-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
44 lines (35 loc) · 1.21 KB
/
background.js
File metadata and controls
44 lines (35 loc) · 1.21 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
async function ensureOffscreenDocument() {
const hasDoc = await chrome.offscreen.hasDocument?.();
if (!hasDoc) {
await chrome.offscreen.createDocument({
url: "offscreen.html",
reasons: ["AUDIO_PLAYBACK"],
justification: "Lecture du son de capture"
});
}
}
async function playShutterSound() {
try {
await ensureOffscreenDocument();
await chrome.runtime.sendMessage({ type: "PLAY_SHUTTER" });
} catch (e) {
console.warn("Erreur lecture son :", e);
}
}
chrome.action.onClicked.addListener(async (tab) => {
if (!tab?.id) return;
try {
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content/clean.js"]
});
await new Promise(r => setTimeout(r, 300));
const dataUrl = await chrome.tabs.captureVisibleTab(tab.windowId, { format: "png" });
const d = new Date(), p = n => String(n).padStart(2, "0");
const filename = `cleanshot-${d.getFullYear()}${p(d.getMonth()+1)}${p(d.getDate())}-${p(d.getHours())}${p(d.getMinutes())}${p(d.getSeconds())}.png`;
await chrome.downloads.download({ url: dataUrl, filename });
await playShutterSound();
} catch (err) {
console.error("Clean Screenshot error:", err);
}
});