commit 47f1550092667fae418a42ff20b7b4064aa3074b Author: Mike Burns Date: Thu May 8 09:58:39 2025 +0200 initial commit v1.0.0 diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..39b0a4b Binary files /dev/null and b/icon.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..f77cb74 --- /dev/null +++ b/manifest.json @@ -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"] +} diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..7e31080 --- /dev/null +++ b/popup.css @@ -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; +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..a47dfb6 --- /dev/null +++ b/popup.html @@ -0,0 +1,11 @@ + + + + + + + Save tabs to file + Restore tabs from file + + + diff --git a/popup.js b/popup.js new file mode 100755 index 0000000..7a6ed5a --- /dev/null +++ b/popup.js @@ -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;