diff --git a/background.js b/background.js new file mode 100644 index 0000000..0653675 --- /dev/null +++ b/background.js @@ -0,0 +1,30 @@ +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 + } +}); diff --git a/icon-off.png b/icon-off.png new file mode 100644 index 0000000..a008a78 Binary files /dev/null and b/icon-off.png differ diff --git a/icon-off.png:Zone.Identifier b/icon-off.png:Zone.Identifier new file mode 100644 index 0000000..e69de29 diff --git a/icon-on.png b/icon-on.png new file mode 100644 index 0000000..18c4369 Binary files /dev/null and b/icon-on.png differ diff --git a/icon-on.png:Zone.Identifier b/icon-on.png:Zone.Identifier new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index 1afe825..f595c0f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,17 +1,14 @@ { "manifest_version": 3, "name": "Live Site Overlay Tool", - "version": "1.0", + "version": "1.1", "description": "Overlay one live site over another for pixel-perfect comparison.", - "permissions": ["scripting", "activeTab"], + "permissions": ["scripting", "activeTab", "tabs", "storage"], "host_permissions": [""], "action": { - "default_title": "Overlay a site" + "default_title": "Toggle Overlay" }, - "content_scripts": [ - { - "matches": [""], - "js": ["content.js"] - } - ] + "background": { + "service_worker": "background.js" + } }