Compare commits

..

2 Commits

Author SHA1 Message Date
1ebd2708e3 Merge branch 'main' of gitea.moe:lamp/vrchat-emoji-manager 2023-10-28 02:00:13 -07:00
a2ca2065cd paste 2023-10-28 02:00:03 -07:00

View File

@ -49,7 +49,7 @@ function createAnimationStyleSelect() {
addbtn.onclick = async () => { addbtn.onclick = async () => {
var fsfhs = await showOpenFilePicker({ var fileHandles = await showOpenFilePicker({
id: "add", id: "add",
multiple: true, multiple: true,
types: [ types: [
@ -61,12 +61,31 @@ addbtn.onclick = async () => {
} }
] ]
}); });
if (!fsfhs.length) return; if (!fileHandles.length) return;
var files = [];
for (let fileHandle of fileHandles) {
try {
files.push(await fileHandle.getFile());
} catch (error) {
displayError(error);
}
}
await addFiles(files);
};
document.body.onpaste = event => {
if (event.clipboardData.files.length) {
addFiles(event.clipboardData.files);
}
};
async function addFiles(files) {
var newEmojis = []; var newEmojis = [];
var errors = []; var errors = [];
for (let fsfh of fsfhs) { for (let file of files) {
try { try {
let file = await fsfh.getFile();
let image = await loadImage(URL.createObjectURL(file)); let image = await loadImage(URL.createObjectURL(file));
let width = image.width; let width = image.width;
let height = image.height; let height = image.height;
@ -119,7 +138,10 @@ addbtn.onclick = async () => {
emojis ||= []; emojis ||= [];
emojis = emojis.concat(newEmojis); emojis = emojis.concat(newEmojis);
await chrome.storage.local.set({emojis}); await chrome.storage.local.set({emojis});
}; }
var deleteMode = false; var deleteMode = false;
@ -261,6 +283,7 @@ function createEmojiSquare(emoji, url) {
if (this.dataset.state == "pending") return; if (this.dataset.state == "pending") return;
var selectedState = this.dataset.state; var selectedState = this.dataset.state;
this.dataset.state = "pending"; this.dataset.state = "pending";
div.querySelector("select").disabled = true;
errorDiv.innerText = ""; errorDiv.innerText = "";
if (deleteMode) { if (deleteMode) {
@ -286,6 +309,7 @@ function createEmojiSquare(emoji, url) {
// disable // disable
callContentScript("deleteEmoji", this.dataset.currentId).then(() => { callContentScript("deleteEmoji", this.dataset.currentId).then(() => {
this.dataset.state = "disabled"; this.dataset.state = "disabled";
div.querySelector("select").disabled = false;
}).catch(error => { }).catch(error => {
displayError(error); displayError(error);
this.dataset.state = selectedState; this.dataset.state = selectedState;
@ -300,6 +324,7 @@ function createEmojiSquare(emoji, url) {
chrome.storage.local.set({emojis}); chrome.storage.local.set({emojis});
this.dataset.currentId = newEmoji.id; this.dataset.currentId = newEmoji.id;
this.dataset.state = "enabled"; this.dataset.state = "enabled";
div.querySelector("select").disabled = false;
}); });
}).catch(error => { }).catch(error => {
this.dataset.state = selectedState; this.dataset.state = selectedState;