mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 06:50:01 -04:00
semicolons
This commit is contained in:
parent
56767f5b31
commit
4906b71e47
37 changed files with 789 additions and 784 deletions
|
@ -1,11 +1,11 @@
|
|||
import { decodeUrl } from "../shared/rewriters/url"
|
||||
import { decodeUrl } from "../shared/rewriters/url";
|
||||
import {
|
||||
encodeUrl,
|
||||
rewriteCss,
|
||||
rewriteHtml,
|
||||
rewriteJs,
|
||||
rewriteSrcset,
|
||||
} from "./shared"
|
||||
} from "./shared";
|
||||
|
||||
const attrObject = {
|
||||
nonce: [HTMLElement],
|
||||
|
@ -25,93 +25,93 @@ const attrObject = {
|
|||
srcdoc: [HTMLIFrameElement],
|
||||
srcset: [HTMLImageElement, HTMLSourceElement],
|
||||
imagesrcset: [HTMLLinkElement],
|
||||
}
|
||||
};
|
||||
|
||||
const attrs = Object.keys(attrObject)
|
||||
const attrs = Object.keys(attrObject);
|
||||
|
||||
for (const attr of attrs) {
|
||||
for (const element of attrObject[attr]) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(element.prototype, attr)
|
||||
const descriptor = Object.getOwnPropertyDescriptor(element.prototype, attr);
|
||||
Object.defineProperty(element.prototype, attr, {
|
||||
get() {
|
||||
if (/src|href|data|action|formaction/.test(attr)) {
|
||||
return decodeUrl(descriptor.get.call(this))
|
||||
return decodeUrl(descriptor.get.call(this));
|
||||
}
|
||||
|
||||
if (this.__origattrs[attr]) {
|
||||
return this.__origattrs[attr]
|
||||
return this.__origattrs[attr];
|
||||
}
|
||||
|
||||
return descriptor.get.call(this)
|
||||
return descriptor.get.call(this);
|
||||
},
|
||||
|
||||
set(value) {
|
||||
this.__origattrs[attr] = value
|
||||
this.__origattrs[attr] = value;
|
||||
|
||||
if (/nonce|integrity|csp/.test(attr)) {
|
||||
return
|
||||
return;
|
||||
} else if (/src|href|data|action|formaction/.test(attr)) {
|
||||
// @ts-expect-error
|
||||
if (value instanceof TrustedScriptURL) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
value = encodeUrl(value)
|
||||
value = encodeUrl(value);
|
||||
} else if (attr === "srcdoc") {
|
||||
value = rewriteHtml(value)
|
||||
value = rewriteHtml(value);
|
||||
} else if (/(image)?srcset/.test(attr)) {
|
||||
value = rewriteSrcset(value)
|
||||
value = rewriteSrcset(value);
|
||||
}
|
||||
|
||||
descriptor.set.call(this, value)
|
||||
descriptor.set.call(this, value);
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Element {
|
||||
__origattrs: Record<string, string>
|
||||
__origattrs: Record<string, string>;
|
||||
}
|
||||
}
|
||||
|
||||
Element.prototype.__origattrs = {}
|
||||
Element.prototype.__origattrs = {};
|
||||
|
||||
Element.prototype.getAttribute = new Proxy(Element.prototype.getAttribute, {
|
||||
apply(target, thisArg, argArray) {
|
||||
if (attrs.includes(argArray[0]) && thisArg.__origattrs[argArray[0]]) {
|
||||
return thisArg.__origattrs[argArray[0]]
|
||||
return thisArg.__origattrs[argArray[0]];
|
||||
}
|
||||
|
||||
return Reflect.apply(target, thisArg, argArray)
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
Element.prototype.setAttribute = new Proxy(Element.prototype.setAttribute, {
|
||||
apply(target, thisArg, argArray) {
|
||||
if (attrs.includes(argArray[0])) {
|
||||
thisArg.__origattrs[argArray[0]] = argArray[1]
|
||||
thisArg.__origattrs[argArray[0]] = argArray[1];
|
||||
if (/nonce|integrity|csp/.test(argArray[0])) {
|
||||
return
|
||||
return;
|
||||
} else if (/src|href|data|action|formaction/.test(argArray[0])) {
|
||||
argArray[1] = encodeUrl(argArray[1])
|
||||
argArray[1] = encodeUrl(argArray[1]);
|
||||
} else if (argArray[0] === "srcdoc") {
|
||||
argArray[1] = rewriteHtml(argArray[1])
|
||||
argArray[1] = rewriteHtml(argArray[1]);
|
||||
} else if (/(image)?srcset/.test(argArray[0])) {
|
||||
argArray[1] = rewriteSrcset(argArray[1])
|
||||
argArray[1] = rewriteSrcset(argArray[1]);
|
||||
} else if (argArray[1] === "style") {
|
||||
argArray[1] = rewriteCss(argArray[1])
|
||||
argArray[1] = rewriteCss(argArray[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return Reflect.apply(target, thisArg, argArray)
|
||||
return Reflect.apply(target, thisArg, argArray);
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
const innerHTML = Object.getOwnPropertyDescriptor(
|
||||
Element.prototype,
|
||||
"innerHTML"
|
||||
)
|
||||
);
|
||||
|
||||
Object.defineProperty(Element.prototype, "innerHTML", {
|
||||
set(value) {
|
||||
|
@ -120,14 +120,14 @@ Object.defineProperty(Element.prototype, "innerHTML", {
|
|||
this instanceof HTMLScriptElement &&
|
||||
!(value instanceof TrustedScript)
|
||||
) {
|
||||
value = rewriteJs(value)
|
||||
value = rewriteJs(value);
|
||||
} else if (this instanceof HTMLStyleElement) {
|
||||
value = rewriteCss(value)
|
||||
value = rewriteCss(value);
|
||||
// @ts-expect-error
|
||||
} else if (!(value instanceof TrustedHTML)) {
|
||||
value = rewriteHtml(value)
|
||||
value = rewriteHtml(value);
|
||||
}
|
||||
|
||||
return innerHTML.set.call(this, value)
|
||||
return innerHTML.set.call(this, value);
|
||||
},
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue