From 9333545ae854bea9dc17ddeb9db310493e5332cd Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 13 Feb 2022 18:57:38 +0300 Subject: [PATCH] Fixed an infinite loop #34 --- src/assets/javascripts/helpers/common.js | 3 +++ src/assets/javascripts/helpers/reddit.js | 24 +++++++++++------------ src/assets/javascripts/helpers/twitter.js | 12 ++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js index 07bbccb..bc9488e 100644 --- a/src/assets/javascripts/helpers/common.js +++ b/src/assets/javascripts/helpers/common.js @@ -103,6 +103,9 @@ function processDefaultCustomInstances( let nameDefaultRedirects; function calcNameCheckBoxes() { + browser.storage.sync.getBytesInUse(null).then( + (result) => console.log(result) + ) let isTrue = true; for (const item of nameHelper.getRedirects()[name].normal) if (!nameDefaultRedirects.includes(item)) { diff --git a/src/assets/javascripts/helpers/reddit.js b/src/assets/javascripts/helpers/reddit.js index 8e85ec7..21ea723 100644 --- a/src/assets/javascripts/helpers/reddit.js +++ b/src/assets/javascripts/helpers/reddit.js @@ -75,12 +75,24 @@ function setLibredditRedirects(val) { redirects.libreddit = val; browser.storage.sync.set({ redditRedirects: redirects }) console.log("libredditRedirects:", val) + for (const item of libredditRedirectsChecks) + if (!redirects.libreddit.normal.includes(item)) { + var index = libredditRedirectsChecks.indexOf(item); + if (index !== -1) libredditRedirectsChecks.splice(index, 1); + } + setLibredditRedirectsChecks(libredditRedirectsChecks); } function setTedditRedirects(val) { redirects.teddit = val; browser.storage.sync.set({ redditRedirects: redirects }) console.log("tedditRedirects:", val) + for (const item of tedditRedirectsChecks) + if (!redirects.teddit.normal.includes(item)) { + var index = tedditRedirectsChecks.indexOf(item); + if (index !== -1) tedditRedirectsChecks.splice(index, 1); + } + setTedditRedirectsChecks(tedditRedirectsChecks); } @@ -90,12 +102,6 @@ function setLibredditRedirectsChecks(val) { libredditRedirectsChecks = val; browser.storage.sync.set({ libredditRedirectsChecks }) console.log("libredditRedirectsChecks: ", val) - for (const item of libredditRedirectsChecks) - if (!redirects.libreddit.normal.includes(item)) { - var index = libredditRedirectsChecks.indexOf(item); - if (index !== -1) libredditRedirectsChecks.splice(index, 1); - } - setLibredditRedirectsChecks(libredditRedirectsChecks); } let libredditCustomRedirects = []; @@ -112,12 +118,6 @@ function setTedditRedirectsChecks(val) { tedditRedirectsChecks = val; browser.storage.sync.set({ tedditRedirectsChecks }) console.log("tedditRedirectsChecks: ", val) - for (const item of tedditRedirectsChecks) - if (!redirects.teddit.normal.includes(item)) { - var index = tedditRedirectsChecks.indexOf(item); - if (index !== -1) tedditRedirectsChecks.splice(index, 1); - } - setTedditRedirectsChecks(tedditRedirectsChecks); } let tedditCustomRedirects = []; diff --git a/src/assets/javascripts/helpers/twitter.js b/src/assets/javascripts/helpers/twitter.js index e39e704..8e29e4a 100644 --- a/src/assets/javascripts/helpers/twitter.js +++ b/src/assets/javascripts/helpers/twitter.js @@ -94,6 +94,12 @@ function setRedirects(val) { redirects.nitter = val; browser.storage.sync.set({ twitterRedirects: redirects }) console.log("twitterRedirects:", val) + for (const item of nitterRedirectsChecks) + if (!redirects.nitter.normal.includes(item)) { + var index = nitterRedirectsChecks.indexOf(item); + if (index !== -1) nitterRedirectsChecks.splice(index, 1); + } + setNitterRedirectsChecks(nitterRedirectsChecks); } let nitterRedirectsChecks; @@ -101,12 +107,6 @@ const getNitterRedirectsChecks = () => nitterRedirectsChecks; function setNitterRedirectsChecks(val) { nitterRedirectsChecks = val; browser.storage.sync.set({ nitterRedirectsChecks }) - for (const item of nitterRedirectsChecks) - if (!redirects.nitter.normal.includes(item)) { - var index = nitterRedirectsChecks.indexOf(item); - if (index !== -1) nitterRedirectsChecks.splice(index, 1); - } - setNitterRedirectsChecks(nitterRedirectsChecks); console.log("nitterRedirectsChecks: ", val) }