add search of images

Similar to texts
This commit is contained in:
buzz-lightsnack-2007 2024-04-24 16:25:55 +08:00
parent ca15164def
commit 0df989512c
2 changed files with 41 additions and 0 deletions

23
scripts/strings/image.js Normal file
View file

@ -0,0 +1,23 @@
const CONFIG = chrome.runtime.getURL("media/config.icons.json");
class Image {
/* Get the appropriate image path from the configuration.
@param {string} name The name of the image.
*/
static get(name, size) {
return (fetch(CONFIG)
.then((response) => response.json())
.then((jsonData) => {
let image = {'raw': jsonData[name]};
image[`filtered`] = (image[`raw`] && size) ? image[`raw`][String(size)] : image[`raw`];
return image[`filtered`];
})
.catch((error) => {
console.error(error);
}));
};
}
export {Image as default};