popup window instead of popup widget for chromium compatability

This commit is contained in:
Mike Burns 2025-05-13 12:34:33 +02:00
parent 47f1550092
commit 9863115881
6 changed files with 42 additions and 12 deletions

0
README.md Normal file
View File

12
background.js Normal file
View File

@ -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,
});
});
});

View File

@ -7,8 +7,9 @@
"icons": { "icons": {
"256": "icon.png" "256": "icon.png"
}, },
"action": { "action": {},
"default_popup": "popup.html" "background": {
"service_worker": "background.js"
}, },
"permissions": ["tabs"] "permissions": ["tabs"]
} }

View File

@ -1,10 +1,12 @@
html, body { html,
body {
padding: 0; padding: 0;
margin: 0; margin: 0;
font-size: 1em; font-size: 1em;
overflow: hidden;
} }
a { div.link {
text-decoration: none; cursor: pointer;
color: #000; color: #000;
display: block; display: block;
padding: 10px 20px; padding: 10px 20px;
@ -12,7 +14,7 @@ a {
background-color: #ccc; background-color: #ccc;
white-space: nowrap; white-space: nowrap;
} }
a:hover { div.link:hover {
background-color: #999; background-color: #999;
color: #fff; color: #fff;
} }

View File

@ -4,8 +4,8 @@
<link rel="stylesheet" href="popup.css" /> <link rel="stylesheet" href="popup.css" />
</head> </head>
<body> <body>
<a href="#" class="save">Save tabs to file</a> <div class="link save">Save tabs to file</div>
<a href="#" class="restore">Restore tabs from file</a> <div class="link restore">Restore tabs from file</div>
<script src="popup.js"></script> <script src="popup.js"></script>
</body> </body>
</html> </html>

View File

@ -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) { async function save(event) {
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
@ -7,12 +18,15 @@ async function save(event) {
// tabs are separated by newline // tabs are separated by newline
const _windows = await chrome.windows.getAll({ populate: true }); const _windows = await chrome.windows.getAll({ populate: true });
_windows.forEach((_window, _windowIndex) => { _windows.forEach((_window, _windowIndex) => {
// ignore this popup window
if (_window.id == currentWindow.id) return;
_window.tabs.forEach((_tab, _tabIndex) => { _window.tabs.forEach((_tab, _tabIndex) => {
content += _tab.url + "\n"; content += _tab.url + "\n";
}); });
content += "\n"; content += "\n";
}); });
const fileHandle = await showSaveFilePicker(); const fileHandle = await showSaveFilePicker();
const writable = await fileHandle.createWritable(); const writable = await fileHandle.createWritable();
await writable.write(content); await writable.write(content);
@ -42,7 +56,8 @@ async function restore(event) {
tabs.push(line); tabs.push(line);
} }
}); });
window.close();
} }
document.querySelector("a.save").onclick = save; document.querySelector("div.link.save").addEventListener("click", save);
document.querySelector("a.restore").onclick = restore; document.querySelector("div.link.restore").addEventListener("click", restore);