Treat all tweets as elements so we dont need to cast
This commit is contained in:
@ -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')
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user