diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-02-12 20:40:36 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-02-12 20:40:36 +0300 |
commit | 531e7c5fb4c6d0bc9e15a2d04ee9e0188b11e0d0 (patch) | |
tree | 4fb12639d0ac0f1f2b360fe3169392a5f8621be2 /src/assets | |
parent | Added redirecting feature #6, will improve it (diff) | |
download | libredirect-531e7c5fb4c6d0bc9e15a2d04ee9e0188b11e0d0.zip |
Rewrote Exceptions logic and design #29
Diffstat (limited to 'src/assets')
-rw-r--r-- | src/assets/javascripts/data.js | 12 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/common.js | 1 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/exceptions.js | 35 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/youtube/youtube.js | 4 |
4 files changed, 37 insertions, 15 deletions
diff --git a/src/assets/javascripts/data.js b/src/assets/javascripts/data.js deleted file mode 100644 index bf0666ba..00000000 --- a/src/assets/javascripts/data.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; - -let theme; -function setTheme(val) { - theme = val; - browser.storage.sync.set({ theme }) -}; - -export default { - theme, - setTheme, -} \ No newline at end of file diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js index 74f8edf5..e6d4895f 100644 --- a/src/assets/javascripts/helpers/common.js +++ b/src/assets/javascripts/helpers/common.js @@ -4,7 +4,6 @@ import instagramHelper from "./instagram.js"; import mediumHelper from "./medium.js"; import redditHelper from "./reddit.js"; import searchHelper from "./search.js"; -import data from '../data.js' import translateHelper from "./translate.js"; import wikipediaHelper from "./wikipedia.js"; import mapsHelper from "./maps.js"; diff --git a/src/assets/javascripts/helpers/exceptions.js b/src/assets/javascripts/helpers/exceptions.js new file mode 100644 index 00000000..9b7f1b59 --- /dev/null +++ b/src/assets/javascripts/helpers/exceptions.js @@ -0,0 +1,35 @@ +"use strict"; + +let exceptions = { + "url": [], + "regex": [], +}; +const getExceptions = () => exceptions; +function setExceptions(val) { + exceptions = val; + browser.storage.sync.set({ exceptions }) + console.log("exceptions: ", val) +} + +async function init() { + let result = await browser.storage.sync.get("exceptions"); + if (result.exceptions) exceptions = result.exceptions; +} + +function isException(url) { + for (const item of exceptions.url) { + console.log(item, `${url.protocol}//${url.host}`) + if (item == `${url.protocol}//${url.host}`) return true; + } + for (const item of exceptions.regex) + if (new RegExp(item).test(url.href)) return true; + return false; +} + +export default { + getExceptions, + setExceptions, + + isException, + init, +} \ No newline at end of file diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js index be20b726..b8665dff 100644 --- a/src/assets/javascripts/helpers/youtube/youtube.js +++ b/src/assets/javascripts/helpers/youtube/youtube.js @@ -5,12 +5,12 @@ import commonHelper from '../common.js' window.browser = window.browser || window.chrome; const targets = [ - /https?:\/\/(www\.|music|m)youtube\.com(\/.*|$)/, + /https?:\/\/(www\.|music\.|m\.|)youtube\.com(\/.*|$)/, /https?:\/\/img\.youtube\.com\/vi\/.*\/..*/, // https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api /https?:\/\/(i|s)\.ytimg\.com\/vi\/.*\/..*/, - /https?:\/\/(www\.|music|)youtube\.com\/watch\?v\=..*/, + /https?:\/\/(www\.|music\.|)youtube\.com\/watch\?v\=..*/, /https?:\/\/youtu\.be\/..*/, |