refactor: revert everything related to loading state

This commit is contained in:
wanhose 2021-07-21 11:59:54 +02:00
parent 47e987b1ee
commit 787fc2ed9b
3 changed files with 1 additions and 65 deletions

View File

@ -169,40 +169,6 @@ const updateCache = (hostname, state) => {
});
};
/**
* @function updateState
* @description Set an extension state
*
* @param {string} [tabId]
* @param {string} [state]
*/
const updateState = (tabId, state) => {
switch (state) {
case "loading":
chrome.tabs.insertCSS(
tabId,
{
file: "styles/content.css",
runAt: "document_start",
},
() => chrome.runtime.lastError
);
break;
case "ready":
chrome.tabs.removeCSS(
tabId,
{
file: "styles/content.css",
},
() => chrome.runtime.lastError
);
break;
default:
break;
}
};
/**
* @description Listens to messages
*/
@ -243,9 +209,6 @@ chrome.runtime.onMessage.addListener((request, sender, responseCallback) => {
case "UPDATE_CACHE":
updateCache(request.hostname, request.state);
break;
case "UPDATE_STATE":
if (hasPermission) updateState(tabId, request.state);
break;
default:
break;
}

View File

@ -22,14 +22,6 @@ const dispatch = chrome.runtime.sendMessage;
let intervalId = 0;
/**
* @var loading
* @description Is extension loading?
* @type {boolean}
*/
let loading = true;
/**
* @var selectorsFromCache
* @description Array of selectors
@ -59,7 +51,6 @@ 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 (!loading) dispatch({ state: "ready", type: "UPDATE_STATE" });
};
/**
@ -99,10 +90,7 @@ const removeFromCache = () => {
if (element) {
const tagName = element.tagName.toUpperCase();
if (!["BODY", "HTML"].includes(tagName)) {
element.remove();
loading = false;
}
if (!["BODY", "HTML"].includes(tagName)) element.remove();
}
}
};
@ -122,7 +110,6 @@ const removeFromNetwork = () => {
if (!["BODY", "HTML"].includes(tagName)) {
element.remove();
loading = false;
dispatch({
hostname: document.location.hostname,
state: { matches: [selector] },
@ -139,10 +126,6 @@ const removeFromNetwork = () => {
*/
const runTasks = () => {
if (attempts >= 5 || selectorsFromCache.length === 0) {
loading = false;
}
if (attempts <= 20) {
fix();
removeFromCache();
@ -166,7 +149,6 @@ dispatch(
dispatch({ type: "ENABLE_POPUP" });
if (enabled) {
dispatch({ state: "loading", type: "UPDATE_STATE" });
selectorsFromCache = matches;
dispatch({ type: "ENABLE_ICON" });
dispatch({ type: "GET_LIST" }, null, ({ selectors }) => {

View File

@ -1,9 +0,0 @@
body {
opacity: 0;
}
@media (prefers-color-scheme: dark) {
html {
background-color: #424242;
}
}