Update element fill to replace `file` URIs in image tags

上级 2b3d2933
......@@ -25,9 +25,6 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
// tslint:disable-next-line:no-any
return oldCreateElement.call(document, tagName as any);
};
if (tagName === "style") {
const style = createElement("style");
// tslint:disable-next-line:no-any
const getPropertyDescriptor = (object: any, id: string): PropertyDescriptor | undefined => {
let op = Object.getPrototypeOf(object);
......@@ -37,6 +34,28 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
return Object.getOwnPropertyDescriptor(op, id);
};
if (tagName === "img") {
const img = createElement("img");
const oldSrc = getPropertyDescriptor(img, "src");
if (!oldSrc) {
throw new Error("Failed to find src property");
}
Object.defineProperty(img, "src", {
get: (): string => {
return oldSrc!.get!.call(img);
},
set: (value: string): void => {
value = value.replace(/file:\/\//g, "/resource");
oldSrc!.set!.call(img, value);
},
});
return img;
}
if (tagName === "style") {
const style = createElement("style");
const oldInnerHtml = getPropertyDescriptor(style, "innerHTML");
if (!oldInnerHtml) {
throw new Error("Failed to find innerHTML property");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册