From f0a4673ce8109a6657f5a556c881aae079b5abbd Mon Sep 17 00:00:00 2001 From: wanhose Date: Thu, 1 Jul 2021 15:11:32 +0200 Subject: [PATCH] feat(scripts): implement content state methods --- scripts/content.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/content.js b/scripts/content.js index e2d2485..5e25d1b 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -59,8 +59,7 @@ const fix = () => { if (body) body.style.setProperty("overflow-y", "unset", "important"); if (facebook) facebook.style.setProperty("position", "unset", "important"); if (html) html.style.setProperty("overflow-y", "unset", "important"); - if (body && !loading) body.style.setProperty("opacity", "1"); - if (html && !loading) html.style.setProperty("background-color", "initial"); + if (!loading) dispatch({ state: "ready", type: "UPDATE_STATE" }); }; /** @@ -148,7 +147,7 @@ const runTasks = () => { fix(); removeFromCache(); if (attempts <= 5) removeFromNetwork(); - if (document.readyState !== "loading") attempts += 1; + if (document.readyState === "complete") attempts += 1; } if (attempts > 20) { @@ -163,20 +162,17 @@ const runTasks = () => { dispatch( { hostname: document.location.hostname, type: "GET_CACHE" }, null, - async ({ enabled, matches }) => { + ({ enabled, matches }) => { dispatch({ type: "ENABLE_POPUP" }); if (enabled) { + dispatch({ state: "loading", type: "UPDATE_STATE" }); selectorsFromCache = matches; dispatch({ type: "ENABLE_ICON" }); - dispatch({ type: "GET_LIST" }, null, async ({ selectors }) => { + dispatch({ type: "GET_LIST" }, null, ({ selectors }) => { selectorsFromNetwork = selectors; intervalId = setInterval(runTasks, 500); }); - } else { - document.addEventListener("DOMContentLoaded", () => { - document.body.style.setProperty("opacity", "1", "important"); - }); } } );