From 7881d89c20e9aad46604deecab4f9f72769d1c79 Mon Sep 17 00:00:00 2001 From: Pionxzh Date: Wed, 11 Jan 2023 20:41:17 +0800 Subject: [PATCH] fix: filter out content policy danger closes #33 --- packages/userscript/src/main.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/userscript/src/main.ts b/packages/userscript/src/main.ts index e176252..7f8362f 100644 --- a/packages/userscript/src/main.ts +++ b/packages/userscript/src/main.ts @@ -212,21 +212,28 @@ function getConversation(): Conversation[] { } function parseTextNode(textNode: HTMLDivElement): ConversationLine[] { - const warningBoxClass = 'bg-orange-500/10' + const warningClassName = 'bg-orange-500/10' + const dangerClassName = 'bg-red-500/10' + const childNodes = textNode.childNodes ? Array.from(textNode.childNodes) : [] const validChildNodes = childNodes.filter((c) => { - // filter out non-element and non-text nodes - if (!(c instanceof Element || c instanceof Text)) return false + if (c instanceof Text) return true // filter out the alert box - return !(c instanceof Element && c.classList.contains(warningBoxClass)) + if (c instanceof Element) { + return !(c.classList.contains(warningClassName) || c.classList.contains(dangerClassName)) + } + + // other nodes are not supported + return false }) if (validChildNodes.length === 0) return [[{ type: 'text', text: textNode.textContent ?? '' }]] if (validChildNodes.length === 1 && validChildNodes[0] instanceof Text) return [[{ type: 'text', text: validChildNodes[0].textContent ?? '' }]] const lines: ConversationLine[] = [] Array.from(textNode.children).forEach((child) => { - if (child.classList.contains(warningBoxClass)) return + if (child.classList.contains(warningClassName)) return + if (child.classList.contains(dangerClassName)) return switch (child.tagName.toUpperCase()) { case 'PRE': {