Switch Memos Clipper theme to emerald accent and update image handling logic in popup.js.
This commit is contained in:
17
src/popup.js
17
src/popup.js
@@ -152,8 +152,8 @@ function renderImages() {
|
||||
// Sync keep flags back (dedup may have removed some)
|
||||
state.images = visible;
|
||||
|
||||
const uploadable = visible.filter((img) => !img.src.startsWith("data:")).length;
|
||||
imgCount.textContent = uploadable;
|
||||
const kept = visible.filter((img) => img.keep).length;
|
||||
imgCount.textContent = kept;
|
||||
imagesList.innerHTML = "";
|
||||
|
||||
if (!visible.length) {
|
||||
@@ -176,20 +176,16 @@ function renderImages() {
|
||||
? `inline-image-${i + 1}`
|
||||
: (img.src.split("/").pop().split("?")[0].slice(0, 28) || `image-${i + 1}`);
|
||||
label.textContent = name;
|
||||
if (isDataUri) label.title = "Embedded data URI — cannot be uploaded";
|
||||
|
||||
const remove = document.createElement("button");
|
||||
remove.className = "remove-img";
|
||||
remove.textContent = "×";
|
||||
remove.title = img.keep ? "Exclude this image" : "Include this image";
|
||||
if (isDataUri) {
|
||||
remove.style.display = "none"; // data URIs can't be uploaded anyway
|
||||
}
|
||||
remove.addEventListener("click", () => {
|
||||
img.keep = !img.keep;
|
||||
chip.classList.toggle("skipped", !img.keep);
|
||||
remove.title = img.keep ? "Exclude this image" : "Include this image";
|
||||
const kept = state.images.filter((im) => im.keep && !im.src.startsWith("data:")).length;
|
||||
const kept = state.images.filter((im) => im.keep).length;
|
||||
imgCount.textContent = kept;
|
||||
});
|
||||
|
||||
@@ -260,7 +256,7 @@ sendBtn.addEventListener("click", async () => {
|
||||
// 1. Upload images if requested
|
||||
const imageMap = new Map(); // originalUrl -> resourceName
|
||||
if (attachCheck.checked) {
|
||||
const toUpload = state.images.filter((img) => img.keep && !img.src.startsWith("data:"));
|
||||
const toUpload = state.images.filter((img) => img.keep);
|
||||
let uploaded = 0;
|
||||
for (const img of toUpload) {
|
||||
sendBtn.textContent = `Uploading image ${uploaded + 1}/${toUpload.length}…`;
|
||||
@@ -363,7 +359,10 @@ async function uploadImage(baseUrl, token, img) {
|
||||
const blob = await response.blob();
|
||||
|
||||
// Derive a filename with a valid extension
|
||||
let filename = img.src.split("/").pop().split("?")[0].split("#")[0];
|
||||
let filename = "image";
|
||||
if (!img.src.startsWith("data:")) {
|
||||
filename = img.src.split("/").pop().split("?")[0].split("#")[0] || "image";
|
||||
}
|
||||
// Strip non-filename characters
|
||||
filename = filename.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, 80);
|
||||
// If no extension, infer from MIME type
|
||||
|
||||
Reference in New Issue
Block a user