fix(fenrirrealm): html parsing (#2343)
Co-authored-by: D3ICIDE <D3ICIDE@users.noreply.github.com>
This commit is contained in:
@@ -75,7 +75,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
|||||||
name = 'Fenrir Realm';
|
name = 'Fenrir Realm';
|
||||||
icon = 'src/en/fenrirrealm/icon.png';
|
icon = 'src/en/fenrirrealm/icon.png';
|
||||||
site = 'https://fenrirealm.com';
|
site = 'https://fenrirealm.com';
|
||||||
version = '1.1.0';
|
version = '1.1.1';
|
||||||
imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined;
|
imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined;
|
||||||
|
|
||||||
hideLocked = storage.get('hideLocked');
|
hideLocked = storage.get('hideLocked');
|
||||||
@@ -221,44 +221,78 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
|||||||
const content = json.content;
|
const content = json.content;
|
||||||
|
|
||||||
if (content) {
|
if (content) {
|
||||||
const parsedContent: Chapter = JSON.parse(content);
|
try {
|
||||||
if (parsedContent.type === 'doc') {
|
// Attempt 1: Handle legacy stringified TipTap JSON AST schema
|
||||||
return parsedContent.content
|
const parsedContent: Chapter = JSON.parse(content);
|
||||||
.map(node => {
|
if (parsedContent.type === 'doc') {
|
||||||
if (node.type === 'paragraph') {
|
return parsedContent.content
|
||||||
const innerHtml =
|
.map(node => {
|
||||||
node.content
|
if (node.type === 'paragraph') {
|
||||||
?.map(c => {
|
const innerHtml =
|
||||||
if (c.type === 'text') {
|
node.content
|
||||||
let text = c.text;
|
?.map(c => {
|
||||||
if (c.marks) {
|
if (c.type === 'text') {
|
||||||
for (const mark of c.marks) {
|
let text = c.text;
|
||||||
if (mark.type === 'bold') text = `<b>${text}</b>`;
|
if (c.marks) {
|
||||||
if (mark.type === 'italic') text = `<i>${text}</i>`;
|
for (const mark of c.marks) {
|
||||||
if (mark.type === 'underline')
|
if (mark.type === 'bold') text = `<b>${text}</b>`;
|
||||||
text = `<u>${text}</u>`;
|
if (mark.type === 'italic')
|
||||||
if (mark.type === 'strike')
|
text = `<i>${text}</i>`;
|
||||||
text = `<strike>${text}</strike>`;
|
if (mark.type === 'underline')
|
||||||
if (mark.type === 'link')
|
text = `<u>${text}</u>`;
|
||||||
text = `<a href="${mark.attrs?.href}">${text}</a>`;
|
if (mark.type === 'strike')
|
||||||
|
text = `<strike>${text}</strike>`;
|
||||||
|
if (mark.type === 'link')
|
||||||
|
text = `<a href="${mark.attrs?.href}">${text}</a>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
return text;
|
if (c.type === 'hardBreak') return '<br>';
|
||||||
}
|
return '';
|
||||||
if (c.type === 'hardBreak') return '<br>';
|
})
|
||||||
return '';
|
.join('') || '';
|
||||||
})
|
return `<p>${innerHtml}</p>`;
|
||||||
.join('') || '';
|
}
|
||||||
return `<p>${innerHtml}</p>`;
|
if (node.type === 'heading') {
|
||||||
}
|
const level = node.attrs?.level || 1;
|
||||||
if (node.type === 'heading') {
|
const innerHtml =
|
||||||
const level = node.attrs?.level || 1;
|
node.content?.map(c => c.text).join('') || '';
|
||||||
const innerHtml = node.content?.map(c => c.text).join('') || '';
|
return `<h${level}>${innerHtml}</h${level}>`;
|
||||||
return `<h${level}>${innerHtml}</h${level}>`;
|
}
|
||||||
}
|
return '';
|
||||||
return '';
|
})
|
||||||
})
|
.join('\n');
|
||||||
.join('\n');
|
}
|
||||||
|
} catch {
|
||||||
|
/**
|
||||||
|
* HTML Response Cleaner:
|
||||||
|
* Fenrir Realm inserts anti-scraping & watermark elements:
|
||||||
|
* 1. Scramble hidden divs (`div[aria-hidden="true"]`)
|
||||||
|
* 2. Inline `<style>` blocks
|
||||||
|
* 3. Reader attributions / Copy references (`.reader-attribution`, `[data-fr-attr]`)
|
||||||
|
*/
|
||||||
|
const $ = loadCheerio(content);
|
||||||
|
|
||||||
|
// Remove anti-scraping tags and inline CSS
|
||||||
|
$('div[aria-hidden="true"]').remove();
|
||||||
|
$('p[aria-hidden="true"]').remove();
|
||||||
|
$('.reader-attribution').remove();
|
||||||
|
$('[data-fr-attr]').remove();
|
||||||
|
$('style').remove();
|
||||||
|
|
||||||
|
// Target any remaining text elements containing copy references or bookmarks
|
||||||
|
$('p, div, span, small').each((_, el) => {
|
||||||
|
const text = $(el).text().trim();
|
||||||
|
if (
|
||||||
|
text.startsWith('Copy reference:') ||
|
||||||
|
text.startsWith('Bookmark:')
|
||||||
|
) {
|
||||||
|
$(el).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $.html() || content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +401,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// resolveUrl = (path: string, isNovel?: boolean) =>
|
// resolveUrl = (path: string, isNovel?: boolean) =>
|
||||||
// this.site + '/series/' + path.split('~~')[0];
|
// this.site + '/series/' + path.split('~~')[0];
|
||||||
|
|
||||||
filters = {
|
filters = {
|
||||||
status: {
|
status: {
|
||||||
|
|||||||
Reference in New Issue
Block a user