popup window instead of popup widget for chromium compatability
This commit is contained in:
parent
47f1550092
commit
9863115881
12
background.js
Normal file
12
background.js
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -7,8 +7,9 @@
|
||||
"icons": {
|
||||
"256": "icon.png"
|
||||
},
|
||||
"action": {
|
||||
"default_popup": "popup.html"
|
||||
"action": {},
|
||||
"background": {
|
||||
"service_worker": "background.js"
|
||||
},
|
||||
"permissions": ["tabs"]
|
||||
}
|
||||
|
||||
12
popup.css
12
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>
|
||||
|
||||
21
popup.js
21
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user