From ca6751436b668c3b6bff8225c893d78690e40b23 Mon Sep 17 00:00:00 2001 From: igorlogius <67047467+igorlogius@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:13:22 +0200 Subject: [PATCH] feat/chore: overhaul options page feat: add 2 extra multi-open parameters --- background.js | 27 +++++- manifest.json | 12 ++- options.html | 238 +++++++++++++++++++++++++++----------------------- options.js | 78 +++++++++-------- 4 files changed, 206 insertions(+), 149 deletions(-) diff --git a/background.js b/background.js index 5bbbd1c..24047ff 100644 --- a/background.js +++ b/background.js @@ -7,7 +7,9 @@ let historyCleanUpQueue = []; let containerCleanupTimer = null; let toolbarAction = ""; let deldelay = 30000; // delay until Tmp Containers and History Entries are removed -let multiopen = 3; +let multiopen = 2; +let multiopen2 = 3; +let multiopen3 = 4; let regexList = null; let neverOpenInTempContainerRegexList = null; @@ -249,7 +251,9 @@ async function onStorageChange() { if (usecolors.length < 1) { usecolors = allcolors; } - multiopen = await getFromStorage("number", "multiopen", 3); + multiopen = await getFromStorage("number", "multiopen", 2); + multiopen2 = await getFromStorage("number", "multiopen2", 3); + multiopen3 = await getFromStorage("number", "multiopen3", 4); listmode = await getFromStorage("string", "listmode", "include"); @@ -302,11 +306,26 @@ async function onCommand(command) { } } - if (command === "multiopen") { + if (command.startsWith("multiopen")) { + let repeat = 0; + + switch (command) { + case "multiopen": + repeat = multiopen; + break; + case "multiopen2": + repeat = multiopen2; + break; + case "multiopen3": + repeat = multiopen3; + break; + default: + return; + } let tabs = await browser.tabs.query({ currentWindow: true, active: true }); if (tabs.length > 0) { const atab = tabs[0]; - for (let i = 0; i < multiopen; i++) { + for (let i = 0; i < repeat; i++) { createTempContainerTab(atab.url); } } diff --git a/manifest.json b/manifest.json index 50a4c35..43dc025 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ }, "commands": { "_execute_browser_action": { - "description": "Toolbar button action" + "description": "Toolbar Action" }, "opennewtab": { "description": "Open newtab in temp container" @@ -24,7 +24,13 @@ "description": "Open newtab in same container as current tab" }, "multiopen": { - "description": "Multi-Open current tab url in N temp container tabs" + "description": "Open current tab URL in X TC tabs" + }, + "multiopen2": { + "description": "Open current tab URL in Y TC tabs" + }, + "multiopen3": { + "description": "Open current tab URL in Z TC tabs" } }, "description": "Open the page,tab,link or bookmark in a new temporary container tab", @@ -46,5 +52,5 @@ "tabs" ], "optional_permissions": ["bookmarks", "history"], - "version": "1.1.38" + "version": "1.1.39" } diff --git a/options.html b/options.html index 5d25c47..6cceea0 100644 --- a/options.html +++ b/options.html @@ -5,6 +5,7 @@ body { background-color: lightgrey; padding: 5px; + min-height: 640px; } textarea { width: 100%; @@ -12,140 +13,163 @@ } fieldset { padding: 10px; - } - #permissions { - width: 100%; - } - - #permissions td { - border-bottom: 1px solid gray; + margin: 5px; + border: 1px groove black; }
-

- - Optional permissions for added functionality (?): + + + Additional Functionality -

- - - - - - - - - - - - -
- 1. "Read and modify bookmarks" - Adds the bookmark context entry
- 2. "Access browsing history" - Enables automatic history deletion
-
+ -
- - Toolbar button action (?): + 1. + + Context menu on Bookmarks (?) + + +
+ 2. + + Automatic history deletion (?) -
-

- - Container colors (?): -

- + + Toolbar Action + + + Open TC + with current URL + Open TC with + 'about:newtab'
-
- + > + + + + +
+ + + Multi-Open Shortcut Parameters (?): + + + + X Y + Z + +
diff --git a/options.js b/options.js index de092a3..d52b540 100644 --- a/options.js +++ b/options.js @@ -40,14 +40,14 @@ function onChange(evt) { browser.storage.local.set(obj).catch(console.error); } -document.getElementById("regexstrs_save_btn").addEventListener("click", () => { +document.getElementById("textarea_regexstrs").addEventListener("input", () => { let val = document.getElementById("textarea_regexstrs").value.trim(); setToStorage("textarea_regexstrs", val); }); document - .getElementById("neveropenintcregexstrs_save_btn") - .addEventListener("click", () => { + .getElementById("textarea_neveropenintcregexstrs") + .addEventListener("input", () => { val = document .getElementById("textarea_neveropenintcregexstrs") .value.trim(); @@ -86,7 +86,7 @@ browser.storage.local }) .catch(console.error); -["multiopen"].map((id) => { +["multiopen", "multiopen2", "multiopen3"].map((id) => { browser.storage.local .get(id) .then((obj) => { @@ -107,43 +107,51 @@ browser.storage.local el.addEventListener("input", onChange); }); -["usecolors", "toolbarAction", "listmode"].map((id) => { +/* input[ radio || checkbox ] */ +["toolbarAction", "usecolors", "listmode"].map((id) => { browser.storage.local .get(id) .then((obj) => { - let el = document.getElementById(id); let val = obj[id]; - - for (var i = 0; i < el.options.length; i++) { - if (Array.isArray(val)) { - el.options[i].selected = val.includes(el.options[i].value); - } else { - el.options[i].selected = val == el.options[i].value; + console.debug(id, val); + + /* checkbox */ + if (Array.isArray(val)) { + let els = document.getElementsByName(id); + + for (let el of els) { + if (val.includes(el.value)) { + el.checked = true; + } else { + el.checked = false; + } + + el.addEventListener("click", (evt) => { + const vals = Array.from(document.getElementsByName(evt.target.name)) + .filter((el) => el.checked) + .map((el) => el.value); + + console.debug(evt.target.name, vals); + setToStorage(evt.target.name, vals); + }); + } + } else { + /* radio group, only one active */ + let els = document.getElementsByName(id); + + for (let el of els) { + if (el.value === val) { + el.checked = true; + } else { + el.checked = false; + } + + el.addEventListener("click", (evt) => { + console.debug(evt.target.name, evt.target.value); + setToStorage(evt.target.name, evt.target.value); + }); } } }) .catch(console.error); - - let el = document.getElementById(id); - el.addEventListener("input", () => { - const selectedItems = Array.from(el.selectedOptions).map( - (option) => option.value, - ); - let obj = {}; - if (el.hasAttribute("multiple")) { - obj[id] = selectedItems; - } else { - obj[id] = selectedItems[0]; - } - browser.storage.local.set(obj).catch(console.error); - }); -}); - -document.getElementById("experimentalbtn").addEventListener("click", (el) => { - const dp = document.getElementById("mainForm").style.display; - if (dp === "none") { - document.getElementById("mainForm").style.display = "block"; - } else { - document.getElementById("mainForm").style.display = "none"; - } });