From b270efe77ca3abc7d467370600a10ed172144602 Mon Sep 17 00:00:00 2001 From: Vaibhav <183315953+D3ICIDE@users.noreply.github.com> Date: Thu, 23 Jul 2026 23:07:09 +0530 Subject: [PATCH] fix(fenrirrealm): html parsing (#2343) Co-authored-by: D3ICIDE --- plugins/english/fenrirrealm.ts | 110 +++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 38 deletions(-) diff --git a/plugins/english/fenrirrealm.ts b/plugins/english/fenrirrealm.ts index 62a85de..291dc6c 100644 --- a/plugins/english/fenrirrealm.ts +++ b/plugins/english/fenrirrealm.ts @@ -75,7 +75,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase { name = 'Fenrir Realm'; icon = 'src/en/fenrirrealm/icon.png'; site = 'https://fenrirealm.com'; - version = '1.1.0'; + version = '1.1.1'; imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined; hideLocked = storage.get('hideLocked'); @@ -221,44 +221,78 @@ class FenrirRealmPlugin implements Plugin.PluginBase { const content = json.content; if (content) { - const parsedContent: Chapter = JSON.parse(content); - if (parsedContent.type === 'doc') { - return parsedContent.content - .map(node => { - if (node.type === 'paragraph') { - const innerHtml = - node.content - ?.map(c => { - if (c.type === 'text') { - let text = c.text; - if (c.marks) { - for (const mark of c.marks) { - if (mark.type === 'bold') text = `${text}`; - if (mark.type === 'italic') text = `${text}`; - if (mark.type === 'underline') - text = `${text}`; - if (mark.type === 'strike') - text = `${text}`; - if (mark.type === 'link') - text = `${text}`; + try { + // Attempt 1: Handle legacy stringified TipTap JSON AST schema + const parsedContent: Chapter = JSON.parse(content); + if (parsedContent.type === 'doc') { + return parsedContent.content + .map(node => { + if (node.type === 'paragraph') { + const innerHtml = + node.content + ?.map(c => { + if (c.type === 'text') { + let text = c.text; + if (c.marks) { + for (const mark of c.marks) { + if (mark.type === 'bold') text = `${text}`; + if (mark.type === 'italic') + text = `${text}`; + if (mark.type === 'underline') + text = `${text}`; + if (mark.type === 'strike') + text = `${text}`; + if (mark.type === 'link') + text = `${text}`; + } } + return text; } - return text; - } - if (c.type === 'hardBreak') return '
'; - return ''; - }) - .join('') || ''; - return `

${innerHtml}

`; - } - if (node.type === 'heading') { - const level = node.attrs?.level || 1; - const innerHtml = node.content?.map(c => c.text).join('') || ''; - return `${innerHtml}`; - } - return ''; - }) - .join('\n'); + if (c.type === 'hardBreak') return '
'; + return ''; + }) + .join('') || ''; + return `

${innerHtml}

`; + } + if (node.type === 'heading') { + const level = node.attrs?.level || 1; + const innerHtml = + node.content?.map(c => c.text).join('') || ''; + return `${innerHtml}`; + } + return ''; + }) + .join('\n'); + } + } catch { + /** + * HTML Response Cleaner: + * Fenrir Realm inserts anti-scraping & watermark elements: + * 1. Scramble hidden divs (`div[aria-hidden="true"]`) + * 2. Inline `