Files
lnreader-plugins/plugins/multisrc/fictioneer/custom/lillyonthevalley/chapterTransform.js
T

36 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const scriptContent = loadedCheerio('script')
.toArray()
.map(script => loadedCheerio(script).html())
.find(content => content && content.includes('var gib ='));
if (scriptContent) {
const gibMatch = scriptContent.match(/var gib = (\[.*?\])/);
if (gibMatch) {
const gibArray = eval(gibMatch[1]) as string[];
gibArray.forEach(cssClass => {
loadedCheerio(`.${cssClass}`).remove();
});
}
}
loadedCheerio('ruby').remove();
loadedCheerio('section#chapter-content p *').each((_, el) => {
if (loadedCheerio(el).attr('data-fcnc-rev') !== '1') return;
const textContent = loadedCheerio(el).text().trim();
if (textContent) {
loadedCheerio(el).replaceWith(
Array.from(textContent).reverse().join(''),
);
}
});
return (
loadedCheerio('section#chapter-content > div')
.html()
?.normalize()
.replace(/\u00A0/g, ' ')
.replace(/\u2060/g, '')
.replace(/­/g, '') // ­
.replace(/[\u202F\u2007\u200B]/g, '') || ''
);