major file and function refactoring

This commit is contained in:
SethBurkart123
2023-12-11 07:42:24 +11:00
parent 703e592151
commit ec01eeb1b2
5 changed files with 141 additions and 171 deletions
+8 -15
View File
@@ -2,7 +2,7 @@ import browser from 'webextension-polyfill'
import { GetThresholdOfColor, GetCSSElement } from '../../../SEQTA';
import { lightenAndPaleColor } from './lightenAndPaleColor';
import ColorLuminance from './ColorLuminance';
import { onError } from '../../utils/onError';
import { SettingsState } from '../../../types/storage';
// Helper functions
const setCSSVar = (varName: any, value: any) => document.documentElement.style.setProperty(varName, value);
@@ -76,9 +76,6 @@ export function updateAllColors(storedSetting: any, newColor = null) {
continue;
}
console.log(element);
console.log(element.contentDocument!.documentElement);
(element.contentDocument!.documentElement.childNodes[1] as HTMLIFrameElement).style.color =
DarkMode ? 'white' : 'black';
element.contentDocument!.documentElement.firstChild!.appendChild(
@@ -87,15 +84,11 @@ export function updateAllColors(storedSetting: any, newColor = null) {
}
}
export function getDarkMode() {
return new Promise((resolve, reject) => {
const result = browser.storage.local.get('DarkMode')
function open (result: any) {
if (browser.runtime.lastError) {
return reject(browser.runtime.lastError);
}
resolve(result.DarkMode);
}
result.then(open, onError)
});
export async function getDarkMode() {
try {
const result = await browser.storage.local.get() as SettingsState;
return result.DarkMode;
} catch (error) {
throw error;
}
}
+3
View File
@@ -0,0 +1,3 @@
export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}