From a9f95b3d1de44edf205508233a3526246842bbf3 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Fri, 4 Feb 2022 18:48:24 +0300 Subject: Cleaning and refining settings --- src/pages/options/general/general.html | 106 +++++++++++++++++++++++++++++++++ src/pages/options/general/general.js | 99 ++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 src/pages/options/general/general.html create mode 100644 src/pages/options/general/general.js (limited to 'src/pages/options/general') diff --git a/src/pages/options/general/general.html b/src/pages/options/general/general.html new file mode 100644 index 00000000..8c46c40b --- /dev/null +++ b/src/pages/options/general/general.html @@ -0,0 +1,106 @@ + + + + + + + + LibRedirect Options + + + + + + + +
+
+

Theme

+ +
+ +
+
+

+ Enter a URL or Regular Expression to be excluded from redirects. +

+

+ All requests for or initiating from a URL that matches your exception + will be excluded from redirects. +

+

+ Note - Supports JavaScript regular expressions, excluding the + enclosing forward slashes. +

+
+
+ + + + + + + + + + + +
+

Add Exception

+
+ + + + + + + + +
+
+ +
+ + + + + + + + \ No newline at end of file diff --git a/src/pages/options/general/general.js b/src/pages/options/general/general.js new file mode 100644 index 00000000..4f111469 --- /dev/null +++ b/src/pages/options/general/general.js @@ -0,0 +1,99 @@ +"use strict"; + +import data from "../../../assets/javascripts/data.js"; +import commonHelper from "../../../assets/javascripts/helpers/common.js"; + +import shared from "../shared.js"; + +const domparser = new DOMParser(); + +let themeElement = document.getElementById("theme"); + +window.browser = window.browser || window.chrome; + +function prependExceptionsItem(item, index) { + const li = document.createElement("li"); + li.appendChild(document.createTextNode(item.toString())); + const button = document.createElement("button"); + li.appendChild(button); + document.getElementById("exceptions-items").prepend(li); + const svg = ` + + + `; + button.appendChild(domparser.parseFromString(svg, "image/svg+xml").documentElement); + button.addEventListener("click", () => { + exceptions.splice(index, 1); + browser.storage.sync.set({ exceptions: exceptions }); + li.remove(); + }); +} + +browser.storage.sync.get( + [ + "exceptions", + "theme", + ], + (result) => { + data.theme = result.theme || ""; + themeElement.value = result.theme || ""; + if (result.theme) document.body.classList.add(result.theme); + data.exceptions = result.exceptions || []; + data.exceptions.forEach(prependExceptionsItem); + shared.autocompletes.forEach((value) => { + }); + } +); + +function addToExceptions() { + const input = document.getElementById("new-exceptions-item"); + const type = document.querySelector('input[name="type"]:checked').value; + if (input.value) { + try { + let value = input.value; + new RegExp(input.value); + if (type === "URL") + value = value.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); + + exceptions.push(value); + browser.storage.sync.set({ + exceptions: exceptions, + }); + prependExceptionsItem(value, exceptions.indexOf(value)); + input.value = ""; + } catch (error) { + input.setCustomValidity("Invalid RegExp"); + } + } else { + input.setCustomValidity("Invalid RegExp"); + } +} +document.getElementById("add-to-exceptions").addEventListener("click", addToExceptions); + +themeElement.addEventListener("change", (event) => { + const value = event.target.options[theme.selectedIndex].value; + switch (value) { + case "dark-theme": + document.body.classList.add("dark-theme"); + document.body.classList.remove("light-theme"); + break; + case "light-theme": + document.body.classList.add("light-theme"); + document.body.classList.remove("dark-theme"); + break; + default: + document.body.classList.remove("light-theme"); + document.body.classList.remove("dark-theme"); + } + browser.storage.sync.set({ theme: value }); +}); + +document.querySelector("#update-instances").addEventListener("click", () => { + document.querySelector("#update-instances").innerHTML = '...'; + if (commonHelper.updateInstances()) + document.querySelector("#update-instances").innerHTML = 'Done!'; + else + document.querySelector("#update-instances").innerHTML = 'Failed Miserabely'; +}); -- cgit 1.4.1