From 392ac15a62bcb4a54c2e5a4b72ddd20fcb987202 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 1 Nov 2022 10:31:12 +0800 Subject: [PATCH] Treat all tweets as elements so we dont need to cast --- .../src/newsletters/substack-handler.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/content-handler/src/newsletters/substack-handler.ts b/packages/content-handler/src/newsletters/substack-handler.ts index 438e429af..627cee1f7 100644 --- a/packages/content-handler/src/newsletters/substack-handler.ts +++ b/packages/content-handler/src/newsletters/substack-handler.ts @@ -106,32 +106,26 @@ export class SubstackHandler extends ContentHandler { return dom } - const recurse = (node: Node, f: (node: Node) => void) => { - for (let i = 0; i < node.childNodes.length; i++) { - const child = node.childNodes[i] + const recurse = (node: Element, f: (node: Element) => void) => { + for (let i = 0; i < node.children.length; i++) { + const child = node.children[i] recurse(child, f) f(child) } } - const isHTMLElement = (node: Node): node is HTMLElement => { - return node.nodeType == 1 - } - for (const tweet of Array.from(staticTweets)) { tweet.className = preClassName + 'tweet' tweet.removeAttribute('style') // get all children, rename their class, remove style // elements (style will be handled in the reader) - recurse(tweet, (n: Node) => { - if (isHTMLElement(n)) { - const className = n.className - if (className.startsWith('tweet-')) { - n.className = preClassName + className - } - n.removeAttribute('style') + recurse(tweet, (n: Element) => { + const className = n.className + if (className.startsWith('tweet-')) { + n.className = preClassName + className } + n.removeAttribute('style') }) }