feat: character direct image support.

This commit is contained in:
Rintim 2024-04-21 20:59:55 +08:00
parent 782aa2eea2
commit 9b4b06a3eb
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
1 changed files with 11 additions and 2 deletions

View File

@ -165,8 +165,13 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", {
nameinfo = get.character(name);
}
}
if (!modeimage && nameinfo && nameinfo[4])
let imgPrefixUrl;
if (!modeimage && nameinfo && nameinfo[4]) {
for (const value of nameinfo[4]) {
if (value.startsWith("img:")) {
imgPrefixUrl = value.slice(4);
break;
}
if (value.startsWith("ext:")) {
extimage = value;
break;
@ -181,7 +186,9 @@ Reflect.defineProperty(HTMLDivElement.prototype, "setBackground", {
break;
}
}
if (extimage) src = extimage.replace(/^ext:/, "extension/");
}
if (imgPrefixUrl) src = imgPrefixUrl;
else if (extimage) src = extimage.replace(/^ext:/, "extension/");
else if (dbimage) {
this.setBackgroundDB(dbimage.slice(3));
return this;
@ -225,6 +232,8 @@ HTMLDivElement.prototype.setBackgroundImage = function (img) {
.unique()
.map((v) => `url("${lib.assetURL}${v}")`)
.join(",");
} else if (URL.canParse(img)) {
this.style.backgroundImage = `url("${img}")`;
} else {
this.style.backgroundImage = `url("${lib.assetURL}${img}")`;
}