initial commit v1.0.0

This commit is contained in:
Mike Burns 2025-05-08 09:58:39 +02:00
commit 47f1550092
5 changed files with 91 additions and 0 deletions

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

14
manifest.json Normal file
View File

@ -0,0 +1,14 @@
{
"name": "TabSaver",
"description": "Save all windows and tabs to a local file",
"homepage_url": "https://miketheburns.com/browser-extensions/tabsaver",
"version": "1.0.0",
"manifest_version": 3,
"icons": {
"256": "icon.png"
},
"action": {
"default_popup": "popup.html"
},
"permissions": ["tabs"]
}

18
popup.css Normal file
View File

@ -0,0 +1,18 @@
html, body {
padding: 0;
margin: 0;
font-size: 1em;
}
a {
text-decoration: none;
color: #000;
display: block;
padding: 10px 20px;
border-bottom: 1px solid #999;
background-color: #ccc;
white-space: nowrap;
}
a:hover {
background-color: #999;
color: #fff;
}

11
popup.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<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>
<script src="popup.js"></script>
</body>
</html>

48
popup.js Executable file
View File

@ -0,0 +1,48 @@
async function save(event) {
event.preventDefault();
event.stopImmediatePropagation();
let content = "";
// iterate ghrough all windows and all tabs
// windows are separated by a blank line
// tabs are separated by newline
const _windows = await chrome.windows.getAll({ populate: true });
_windows.forEach((_window, _windowIndex) => {
_window.tabs.forEach((_tab, _tabIndex) => {
content += _tab.url + "\n";
});
content += "\n";
});
const fileHandle = await showSaveFilePicker();
const writable = await fileHandle.createWritable();
await writable.write(content);
await writable.close();
window.close();
}
async function restore(event) {
event.preventDefault();
event.stopImmediatePropagation();
let tabs = [];
const [fileHandle] = await window.showOpenFilePicker();
const file = await fileHandle.getFile();
const contents = await file.text();
// get tabs from text file (each line is a tab, an empty line indicates we can open a window with previous tabs)
contents.split("\n").forEach(async (line) => {
if (line == "" && tabs.length) {
// create new window with tabs in array
chrome.windows.create({
state: "maximized",
url: tabs,
});
tabs = []; // reset tabs array
} else {
// add tab to array
tabs.push(line);
}
});
}
document.querySelector("a.save").onclick = save;
document.querySelector("a.restore").onclick = restore;