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": {
"256": "icon.png"
},
"action": {
"default_popup": "popup.html"
"action": {},
"background": {
"service_worker": "background.js"
},
"permissions": ["tabs"]
}

View File

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

View File

@ -4,8 +4,8 @@
<link rel="stylesheet" href="popup.css" />
</head>
<body>
<a href="#" class="save">Save tabs to file</a>
<a href="#" class="restore">Restore tabs from file</a>
<div class="link save">Save tabs to file</div>
<div class="link restore">Restore tabs from file</div>
<script src="popup.js"></script>
</body>
</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) {
event.preventDefault();
event.stopImmediatePropagation();
@ -7,6 +18,9 @@ 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";
});
@ -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);