Fix uri encoding for preview image

This commit is contained in:
Lawrence Ling
2024-03-01 21:46:22 +11:00
parent e597e7ef18
commit 926a9704c0
+8 -1
View File
@@ -71,6 +71,13 @@ app.registerExtension({
}
});
function encodeRFC3986URIComponent(str) {
return encodeURIComponent(str).replace(
/[!'()*]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
);
}
// After an element is created for an item, add an image if it has one
contextMenuHook["addItem"].push(function (el, menu, [name, value, options]) {
if (el && isCustomItem(value) && value?.image && !value.submenu) {
@@ -78,7 +85,7 @@ app.registerExtension({
$el("div.pysssss-combo-image", {
parent: el,
style: {
backgroundImage: `url(/pysssss/view/${encodeURIComponent(value.image)})`,
backgroundImage: `url(/pysssss/view/${encodeRFC3986URIComponent(value.image)})`,
},
});
}