Fix special characters breaking search in most sources (#1557)

This commit is contained in:
Adam Kemish
2025-03-15 15:35:31 +08:00
committed by GitHub
parent 3a10e24545
commit ea7965bdda
28 changed files with 103 additions and 73 deletions
+34 -19
View File
@@ -45,7 +45,7 @@ class MadaraPlugin implements Plugin.PluginBase {
this.icon = `multisrc/madara/${metadata.id.toLowerCase()}/icon.png`;
this.site = metadata.sourceSite;
const versionIncrements = metadata.options?.versionIncrements || 0;
this.version = `1.0.${6 + versionIncrements}`;
this.version = `1.0.${7 + versionIncrements}`;
this.options = metadata.options;
this.filters = metadata.filters;
@@ -62,26 +62,41 @@ class MadaraPlugin implements Plugin.PluginBase {
translateDragontea(text: Cheerio<AnyNode>): Cheerio<AnyNode> {
if (this.id !== 'dragontea') return text;
const $ = parseHTML(text.html()?.replace('\n', '').replace(/<br\s*\/?>/g, '\n') || '');
const $ = parseHTML(
text
.html()
?.replace('\n', '')
.replace(/<br\s*\/?>/g, '\n') || '',
);
const reverseAlpha = 'zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA';
const forwardAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
text.html($.html());
text.find('*').addBack().contents().filter((_, el) => el.nodeType === 3).each((_, el) => {
const $el = $(el);
const translated = $el.text().normalize('NFD').split('')
.map(char => {
const base = char.normalize('NFC');
const idx = forwardAlpha.indexOf(base);
return idx >= 0 ? reverseAlpha[idx] + char.slice(base.length) : char;
})
.join('');
$el.replaceWith(translated.replace('\n', '<br>'));
});
text
.find('*')
.addBack()
.contents()
.filter((_, el) => el.nodeType === 3)
.each((_, el) => {
const $el = $(el);
const translated = $el
.text()
.normalize('NFD')
.split('')
.map(char => {
const base = char.normalize('NFC');
const idx = forwardAlpha.indexOf(base);
return idx >= 0
? reverseAlpha[idx] + char.slice(base.length)
: char;
})
.join('');
$el.replaceWith(translated.replace('\n', '<br>'));
});
return text;
}
}
getHostname(url: string): string {
url = url.split('/')[2];
@@ -261,7 +276,7 @@ class MadaraPlugin implements Plugin.PluginBase {
if (this.options?.useNewChapterEndpoint) {
html = await fetchApi(this.site + novelPath + 'ajax/chapters/', {
method: 'POST',
referrer: this.site + novelPath
referrer: this.site + novelPath,
}).then(res => res.text());
} else {
const novelId =
@@ -347,7 +362,7 @@ class MadaraPlugin implements Plugin.PluginBase {
'/page/' +
pageNo +
'/?s=' +
searchTerm +
encodeURIComponent(searchTerm) +
'&post_type=wp-manga';
const loadedCheerio = await this.getCheerio(url, true);
return this.parseNovels(loadedCheerio);