From 9863115881bb8ba21d4324b34f8dfbcd479c258a Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Tue, 13 May 2025 12:34:33 +0200 Subject: [PATCH] popup window instead of popup widget for chromium compatability --- README.md | 0 background.js | 12 ++++++++++++ manifest.json | 5 +++-- popup.css | 12 +++++++----- popup.html | 4 ++-- popup.js | 21 ++++++++++++++++++--- 6 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 README.md create mode 100644 background.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/background.js b/background.js new file mode 100644 index 0000000..35f15bc --- /dev/null +++ b/background.js @@ -0,0 +1,12 @@ +chrome.action.onClicked.addListener((tab, event) => { + chrome.windows.getCurrent((window) => { + chrome.windows.create({ + url: "popup.html", + type: "popup", + width: 250, + height: 84, + top: window.top + (window.height - 84) / 2, + left: window.left + (window.width - 250) / 2, + }); + }); +}); diff --git a/manifest.json b/manifest.json index f77cb74..2097cf7 100644 --- a/manifest.json +++ b/manifest.json @@ -7,8 +7,9 @@ "icons": { "256": "icon.png" }, - "action": { - "default_popup": "popup.html" + "action": {}, + "background": { + "service_worker": "background.js" }, "permissions": ["tabs"] } diff --git a/popup.css b/popup.css index 7e31080..0ca4fff 100644 --- a/popup.css +++ b/popup.css @@ -1,10 +1,12 @@ -html, body { +html, +body { padding: 0; margin: 0; font-size: 1em; + overflow: hidden; } -a { - text-decoration: none; +div.link { + cursor: pointer; color: #000; display: block; padding: 10px 20px; @@ -12,7 +14,7 @@ a { background-color: #ccc; white-space: nowrap; } -a:hover { +div.link:hover { background-color: #999; color: #fff; -} \ No newline at end of file +} diff --git a/popup.html b/popup.html index a47dfb6..2052905 100644 --- a/popup.html +++ b/popup.html @@ -4,8 +4,8 @@ - Save tabs to file - Restore tabs from file + + diff --git a/popup.js b/popup.js index 7a6ed5a..76595ef 100755 --- a/popup.js +++ b/popup.js @@ -1,3 +1,14 @@ +let currentWindow; +chrome.windows.getCurrent((_window) => { + currentWindow = _window; +}); + +window.addEventListener("keydown", (event) => { + if (event.keyCode == 27) { + window.close(); + } +}); + async function save(event) { event.preventDefault(); event.stopImmediatePropagation(); @@ -7,12 +18,15 @@ async function save(event) { // tabs are separated by newline const _windows = await chrome.windows.getAll({ populate: true }); _windows.forEach((_window, _windowIndex) => { + // ignore this popup window + if (_window.id == currentWindow.id) return; + _window.tabs.forEach((_tab, _tabIndex) => { content += _tab.url + "\n"; }); content += "\n"; }); - + const fileHandle = await showSaveFilePicker(); const writable = await fileHandle.createWritable(); await writable.write(content); @@ -42,7 +56,8 @@ async function restore(event) { tabs.push(line); } }); + window.close(); } -document.querySelector("a.save").onclick = save; -document.querySelector("a.restore").onclick = restore; +document.querySelector("div.link.save").addEventListener("click", save); +document.querySelector("div.link.restore").addEventListener("click", restore);