mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
clean up storageListeners + fix popup
This commit is contained in:
+1
-1
@@ -739,7 +739,7 @@ export function ColorLuminance(color, lum = 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageListener();
|
new StorageListener();
|
||||||
|
|
||||||
var PageLoaded = false;
|
var PageLoaded = false;
|
||||||
async function CheckLoadOnPeriods() {
|
async function CheckLoadOnPeriods() {
|
||||||
|
|||||||
@@ -10,3 +10,13 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.outside-container {
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
top: 80px;
|
||||||
|
height: 590px;
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/* global chrome */
|
||||||
|
import { ColorLuminance, GetThresholdofHex } from "../../SEQTA.js";
|
||||||
|
|
||||||
|
export function updateDocumentColors(newColor) {
|
||||||
|
const rbg = GetThresholdofHex(newColor);
|
||||||
|
const textColor = rbg > 210 ? "black" : "white";
|
||||||
|
const logo = `url(${chrome.runtime.getURL(
|
||||||
|
`icons/betterseqta-${textColor === "black" ? "dark" : "light"}-full.png`
|
||||||
|
)})`;
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty("--text-color", textColor);
|
||||||
|
document.documentElement.style.setProperty("--betterseqta-logo", logo);
|
||||||
|
document.documentElement.style.setProperty("--better-main", newColor);
|
||||||
|
|
||||||
|
const lightColor =
|
||||||
|
newColor === "#ffffff" ? "#b7b7b7" : ColorLuminance(newColor, 0.99);
|
||||||
|
|
||||||
|
document.documentElement.style.setProperty("--better-light", lightColor);
|
||||||
|
}
|
||||||
@@ -1,70 +1,53 @@
|
|||||||
/* global chrome */
|
/* global chrome */
|
||||||
import { lightenAndPaleColor, GetThresholdofHex, ColorLuminance, CreateCustomShortcutDiv, RemoveCustomShortcutDiv } from "../../SEQTA.js";
|
|
||||||
|
|
||||||
export default function StorageListener() {
|
import {
|
||||||
chrome.storage.onChanged.addListener(function (changes) {
|
CreateCustomShortcutDiv,
|
||||||
|
RemoveCustomShortcutDiv,
|
||||||
|
} from "../../SEQTA.js";
|
||||||
|
import { updateDocumentColors } from "../ui/Colors.js";
|
||||||
|
|
||||||
|
export default class StorageListener {
|
||||||
|
constructor() {
|
||||||
|
chrome.storage.onChanged.addListener(this.handleStorageChanges.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleStorageChanges(changes) {
|
||||||
if (changes.selectedColor) {
|
if (changes.selectedColor) {
|
||||||
try {
|
this.handleSelectedColorChange(changes.selectedColor.newValue);
|
||||||
chrome.storage.local.get(["DarkMode"], function (result) {
|
|
||||||
if (!result.DarkMode) {
|
|
||||||
console.log(changes.selectedColor.newValue);
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--better-pale",
|
|
||||||
lightenAndPaleColor(changes.selectedColor.newValue)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
let rbg = GetThresholdofHex(changes.selectedColor.newValue);
|
|
||||||
|
|
||||||
if (rbg > 210) {
|
|
||||||
document.documentElement.style.setProperty("--text-color", "black");
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--betterseqta-logo",
|
|
||||||
`url(${chrome.runtime.getURL("icons/betterseqta-dark-full.png")})`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
document.documentElement.style.setProperty("--text-color", "white");
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--betterseqta-logo",
|
|
||||||
`url(${chrome.runtime.getURL("icons/betterseqta-light-full.png")})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--better-main",
|
|
||||||
changes.selectedColor.newValue
|
|
||||||
);
|
|
||||||
|
|
||||||
if (changes.selectedColor.newValue == "#ffffff") {
|
|
||||||
document.documentElement.style.setProperty("--better-light", "#b7b7b7");
|
|
||||||
} else {
|
|
||||||
document.documentElement.style.setProperty(
|
|
||||||
"--better-light",
|
|
||||||
ColorLuminance(changes.selectedColor.newValue, 0.99)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes?.customshortcuts?.newValue) {
|
if (changes?.customshortcuts?.newValue) {
|
||||||
console.log(changes);
|
this.handleCustomShortcutsChange(
|
||||||
|
changes.customshortcuts.oldValue,
|
||||||
|
changes.customshortcuts.newValue
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const oldValue = changes.customshortcuts.oldValue;
|
handleSelectedColorChange(newColor) {
|
||||||
const newValue = changes.customshortcuts.newValue;
|
try {
|
||||||
|
chrome.storage.local.get(["DarkMode"], (result) => {
|
||||||
|
if (!result.DarkMode) {
|
||||||
|
updateDocumentColors(newColor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleCustomShortcutsChange(oldValue, newValue) {
|
||||||
// Check for addition
|
// Check for addition
|
||||||
if (newValue.length > oldValue.length) {
|
if (newValue.length > oldValue.length) {
|
||||||
CreateCustomShortcutDiv(newValue[oldValue.length]);
|
CreateCustomShortcutDiv(newValue[oldValue.length]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for removal
|
// Check for removal
|
||||||
else if (newValue.length < oldValue.length) {
|
else if (newValue.length < oldValue.length) {
|
||||||
// Find the removed element
|
|
||||||
const removedElement = oldValue.find(
|
const removedElement = oldValue.find(
|
||||||
(oldItem) => !newValue.some((newItem) => JSON.stringify(oldItem) === JSON.stringify(newItem))
|
(oldItem) =>
|
||||||
|
!newValue.some(
|
||||||
|
(newItem) => JSON.stringify(oldItem) === JSON.stringify(newItem)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (removedElement) {
|
if (removedElement) {
|
||||||
@@ -72,5 +55,4 @@ export default function StorageListener() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user