diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-02-04 18:48:24 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-02-04 18:48:24 +0300 |
commit | a9f95b3d1de44edf205508233a3526246842bbf3 (patch) | |
tree | a273532e131ae36cee2a200c953d015c3fa36bff /src/pages/options/general | |
parent | Added Piped, cleaned code (diff) | |
download | libredirect-a9f95b3d1de44edf205508233a3526246842bbf3.zip |
Cleaning and refining settings
Diffstat (limited to 'src/pages/options/general')
-rw-r--r-- | src/pages/options/general/general.html | 106 | ||||
-rw-r--r-- | src/pages/options/general/general.js | 99 |
2 files changed, 205 insertions, 0 deletions
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 @@ +<!DOCTYPE html> +<html> + +<head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link href="../../stylesheets/styles.css" rel="stylesheet" /> + <title>LibRedirect Options</title> +</head> + +<body class="option"> + + <section class="links"> + <a href="./general.html" class="selected">General</a> + <a href="../youtube/youtube.html">Youtube</a> + <a href="../twitter/twitter.html">Twitter</a> + <a href="../instagram/instagram.html">Instagram</a> + <a href="../reddit/reddit.html">Reddit</a> + <a href="../search/search.html">Search</a> + <a href="../translate/translate.html">Translate</a> + <a href="../maps/maps.html">Maps</a> + <a href="../wikipedia/wikipedia.html">Wikipedia</a> + <a href="../medium/medium.html">Medium</a> + </section> + + + <section class="option-block"> + <div class="some-block option-block"> + <h4>Theme</h4> + <select id="theme"> + <option value="">System</option> + <option value="light-theme">Light</option> + <option value="dark-theme">Dark</option> + </select> + </div> + <div class="buttons buttons-inline"> + <a class="button button-inline" id="update-instances"> + <span>Update Instances</span> + </a> + </div> + <hr> + <section class="settings-block"> + <p data-localise="__MSG_exceptionsDescriptionP1__"> + Enter a URL or Regular Expression to be excluded from redirects. + </p> + <p data-localise="__MSG_exceptionsDescriptionP2__"> + All requests for or initiating from a URL that matches your exception + will be excluded from redirects. + </p> + <p data-localise="__MSG_exceptionsDescriptionP3__"> + Note - Supports JavaScript regular expressions, excluding the + enclosing forward slashes. + </p> + </section> + <section class="settings-block"> + <table class="exceptions option"> + <tbody> + <tr> + <td> + <h1 data-localise="__MSG_addException__">Add Exception</h1> + </td> + </tr> + <tr> + <td> + <input id="new-exceptions-item" type="text" placeholder="URL or RegExp" /> + </td> + <td> + <input type="radio" id="url" name="type" value="URL" checked /> + <label class="radio" for="url">URL</label> + <input type="radio" id="regExp" name="type" value="RegExp" /> + <label class="radio" for="regExp">RegExp</label> + </td> + <td> + <button id="add-to-exceptions"> + <svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"> + <line x1="256" y1="112" x2="256" y2="400" style=" + fill: none; + stroke: #fff; + stroke-linecap: round; + stroke-linejoin: round; + stroke-width: 32px; + " /> + <line x1="400" y1="256" x2="112" y2="256" style=" + fill: none; + stroke: #fff; + stroke-linecap: round; + stroke-linejoin: round; + stroke-width: 32px; + " /> + </svg> + </button> + </td> + </tr> + </tbody> + </table> + </section> + <ul id="exceptions-items"></ul> + </section> + + + <script type="module" src="./general.js"></script> + <script type="module" src="../init.js"></script> + <!-- <script src="../../assets/javascripts/localise.js"></script> --> +</body> + +</html> \ 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 = `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 512 512'> + <line x1='368' y1='368' x2='144' y2='144' + style='fill:none;stroke:#FFF;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px' /> + <line x1='368' y1='144' x2='144' y2='368' + style='fill:none;stroke:#FFF;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px' /> + </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'; +}); |