Make NYTimes more stable, add rewriting for <image> tags.

This commit is contained in:
wearrrrr 2024-09-28 16:39:56 -05:00
parent dc80bf1170
commit b6eb174bfe
2 changed files with 17 additions and 14 deletions

View file

@ -77,16 +77,17 @@ export default function (client: ScramjetClient, self: Self) {
} }
} }
Object.defineProperty(self, "event", { if (!self.event) {
get() { Object.defineProperty(self, "event", {
return argArray[0]; get() {
}, return argArray[0];
configurable: true, },
}); configurable: true,
});
}
let rv = Reflect.apply(target, thisArg, argArray); const rv = Reflect.apply(target, thisArg, argArray);
delete self.event;
return rv; return rv;
}, },

View file

@ -1,5 +1,5 @@
import { ElementType, Parser } from "htmlparser2"; import { ElementType, Parser } from "htmlparser2";
import { ChildNode, DomHandler, Element, Node, Text } from "domhandler"; import { ChildNode, DomHandler, Element } from "domhandler";
import render from "dom-serializer"; import render from "dom-serializer";
import { URLMeta, encodeUrl } from "./url"; import { URLMeta, encodeUrl } from "./url";
import { rewriteCss } from "./css"; import { rewriteCss } from "./css";
@ -68,10 +68,10 @@ export function rewriteHtml(
return render(handler.root); return render(handler.root);
} }
type ParseState = { // type ParseState = {
base: string; // base: string;
origin?: URL; // origin?: URL;
}; // };
export function unrewriteHtml(html: string) { export function unrewriteHtml(html: string) {
const handler = new DomHandler((err, dom) => dom); const handler = new DomHandler((err, dom) => dom);
@ -103,7 +103,7 @@ export function unrewriteHtml(html: string) {
} }
export const htmlRules: { export const htmlRules: {
[key: string]: "*" | string[] | Function; [key: string]: "*" | string[] | ((...any: any[]) => string | null);
fn: (value: string, meta: URLMeta, cookieStore: CookieStore) => string | null; fn: (value: string, meta: URLMeta, cookieStore: CookieStore) => string | null;
}[] = [ }[] = [
{ {
@ -116,6 +116,7 @@ export const htmlRules: {
"embed", "embed",
"script", "script",
"img", "img",
"image",
"iframe", "iframe",
"source", "source",
"video", "video",
@ -128,6 +129,7 @@ export const htmlRules: {
action: ["form"], action: ["form"],
formaction: ["button", "input", "textarea", "submit"], formaction: ["button", "input", "textarea", "submit"],
poster: ["video"], poster: ["video"],
"xlink:href": ["image"],
}, },
{ {
fn: () => null, fn: () => null,