From 540b41ef0a752bf7aa0d90df37bdb69a28b6f39f Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Mon, 31 Jan 2022 21:01:16 +0300 Subject: Refining code. Adding frontend option to search --- src/pages/options/options.js | 98 -------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/pages/options/options.js (limited to 'src/pages/options/options.js') diff --git a/src/pages/options/options.js b/src/pages/options/options.js deleted file mode 100644 index 5d6aed4e..00000000 --- a/src/pages/options/options.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; - -import commonHelper from "../../assets/javascripts/helpers/common.js"; - -import shared from "./shared.js"; - -const domparser = new DOMParser(); - -let themeElement = document.getElementById("theme"); -let exceptions; - -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) => { - themeElement.value = result.theme || ""; - if (result.theme) document.body.classList.add(result.theme); - exceptions = result.exceptions || []; - 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.getInstances()) - document.querySelector("#update-instances").innerHTML = 'Done!'; - else - document.querySelector("#update-instances").innerHTML = 'Failed Miserabely'; -}); -- cgit 1.4.1