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