mirror of
https://github.com/TristanEDU/LiveOverlayExtension.git
synced 2026-01-13 16:18:23 +00:00
- Removed automatic content script injection from manifest - Added background script with click handler for toggling overlay - Overlay is now injected only when extension icon is clicked - Overlay can be removed by clicking the icon again - Prevents unintended injection across multiple tabs of same domain - Per-tab state tracking for clean UX
31 lines
926 B
JavaScript
31 lines
926 B
JavaScript
const tabOverlayStatus = {};
|
|
|
|
chrome.action.onClicked.addListener(async (tab) => {
|
|
const tabId = tab.id;
|
|
|
|
if (tabOverlayStatus[tabId]) {
|
|
// Already injected → remove overlay
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tabId },
|
|
func: () => {
|
|
const iframe = document.getElementById("overlay-iframe");
|
|
const panel = document.querySelector(
|
|
'div[style*="Overlay Controls"]'
|
|
)?.parentElement;
|
|
if (iframe) iframe.remove();
|
|
if (panel) panel.remove();
|
|
},
|
|
});
|
|
tabOverlayStatus[tabId] = false;
|
|
chrome.action.setIcon({ tabId, path: "icon-off.png" }); // optional
|
|
} else {
|
|
// Not injected → inject content.js
|
|
chrome.scripting.executeScript({
|
|
target: { tabId: tabId },
|
|
files: ["content.js"],
|
|
});
|
|
tabOverlayStatus[tabId] = true;
|
|
chrome.action.setIcon({ tabId, path: "icon-on.png" }); // optional
|
|
}
|
|
});
|