Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
71 lines (63 loc) · 1.81 KB
/
Copy pathbackground.js
File metadata and controls
71 lines (63 loc) · 1.81 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
const hasVideoTags = new chrome.declarativeContent.PageStateMatcher({
css: ["video"]
});
// Setup rules on installation
chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [hasVideoTags],
actions: [new chrome.declarativeContent.ShowAction()]
}]);
});
});
// State management helpers
const getTabState = async (tabId) => {
const key = `tab_${tabId}`;
const result = await chrome.storage.session.get(key);
return result[key] || { injected: false, active: false };
};
const setTabState = async (tabId, state) => {
const key = `tab_${tabId}`;
await chrome.storage.session.set({ [key]: state });
};
// Main interaction handler
chrome.action.onClicked.addListener(async (tab) => {
const state = await getTabState(tab.id);
if (!state.injected) {
await chrome.scripting.insertCSS({
target: { tabId: tab.id },
files: ["kitescreen.css"]
});
state.injected = true;
}
if (!state.active) {
// Set icon to exit
await chrome.action.setIcon({
tabId: tab.id,
path: "images/exit128.png"
});
// Execute create.js
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["create.js"]
});
state.active = true;
} else {
// Set icon to default
await chrome.action.setIcon({
tabId: tab.id,
path: "images/icon128.png"
});
// Execute destroy.js
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["destroy.js"]
});
state.active = false;
}
await setTabState(tab.id, state);
});
// Clean up state when tab is closed
chrome.tabs.onRemoved.addListener(async (tabId) => {
await chrome.storage.session.remove(`tab_${tabId}`);
});