Compare commits
2 Commits
779624a722
...
a74163b29a
Author | SHA1 | Date | |
---|---|---|---|
a74163b29a | |||
349c7bd551 |
47
manage.js
47
manage.js
@ -233,6 +233,37 @@ clearbtn.onclick = async () => {
|
||||
await loadToggleState();
|
||||
})().catch(displayError);
|
||||
|
||||
async function refreshImages() {
|
||||
console.debug("refreshImages");
|
||||
var images = await db.getAllImages();
|
||||
for (let image of images) {
|
||||
if (!document.querySelector(`[data-internal-id="${image.internalId}"]`)) createEmojiSquare(image);
|
||||
}
|
||||
var ids = images.map(i => i.internalId);
|
||||
for (let emojisquare of document.querySelectorAll(".emojisquare")) {
|
||||
if (!ids.includes(emojisquare.dataset.internalId)) emojisquare.delete();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadToggleState() {
|
||||
console.debug("loadToggleState");
|
||||
try {
|
||||
var elements = document.querySelectorAll(".emojisquare");
|
||||
if (elements.length === 0) return;
|
||||
var currentFiles = await callContentScript("getFiles", mode);
|
||||
var active = currentFiles?.map(e => e.id);
|
||||
elements.forEach(e => {
|
||||
e.dataset.state = active.includes(e.dataset["currentId_"+mode]) ? "enabled" : "disabled";
|
||||
});
|
||||
errorDiv.innerText = "";
|
||||
} catch (error) {
|
||||
displayError(error);
|
||||
}
|
||||
}
|
||||
|
||||
onfocus = () => refreshImages().then(loadToggleState);
|
||||
|
||||
|
||||
|
||||
function createEmojiSquare({internalId, data, animationStyle, currentId_emoji, currentId_sticker}) {
|
||||
var div = document.createElement("div");
|
||||
@ -326,22 +357,6 @@ function createEmojiSquare({internalId, data, animationStyle, currentId_emoji, c
|
||||
}
|
||||
|
||||
|
||||
async function loadToggleState() {
|
||||
console.debug("loadToggleState");
|
||||
try {
|
||||
var elements = document.querySelectorAll(".emojisquare");
|
||||
if (elements.length === 0) return;
|
||||
var currentFiles = await callContentScript("getFiles", mode);
|
||||
var active = currentFiles?.map(e => e.id);
|
||||
elements.forEach(e => {
|
||||
e.dataset.state = active.includes(e.dataset["currentId_"+mode]) ? "enabled" : "disabled";
|
||||
});
|
||||
errorDiv.innerText = "";
|
||||
} catch (error) {
|
||||
displayError(error);
|
||||
}
|
||||
}
|
||||
onfocus = loadToggleState;
|
||||
|
||||
|
||||
function displayError(error) {
|
||||
|
Loading…
Reference in New Issue
Block a user