@@ -24,6 +24,8 @@ To add a new source you need to add it to sources.json:
|
||||
exists in the languages (check folder names in "plugins/"))
|
||||
- useNewChapterEndpoint: if the source uses the new chapter endpoint
|
||||
- versionIncrements: needs to be updated everytime the site url is updated
|
||||
- customJS: custom javascript that will be excuted when getting the text (if
|
||||
the site has a custom copyright that need to be removed)
|
||||
|
||||
### icon
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ const generator = function generator(source) {
|
||||
});
|
||||
|
||||
const pluginScript = `
|
||||
${madaraTemplate}
|
||||
${madaraTemplate.replace(
|
||||
'// CustomJS HERE',
|
||||
source.options?.customJs || '',
|
||||
)}
|
||||
const plugin = new MadaraPlugin(${JSON.stringify(source)});
|
||||
export default plugin;
|
||||
`.trim();
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
"sourceSite": "https://boxnovel.com/",
|
||||
"sourceName": "BoxNovel",
|
||||
"options": {
|
||||
"useNewChapterEndpoint": true
|
||||
"useNewChapterEndpoint": true,
|
||||
"customJs": "chapterText.find(.cha-tit > div).remove()",
|
||||
"versionIncrements": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -141,7 +143,8 @@
|
||||
"options": {
|
||||
"useNewChapterEndpoint": true,
|
||||
"lang": "Arabic",
|
||||
"versionIncrements": 4
|
||||
"versionIncrements": 5,
|
||||
"customJs": "chapterText.find('span[style*=\"opacity: 0; position: fixed;\"]').remove();"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -301,11 +304,12 @@
|
||||
},
|
||||
{
|
||||
"id": "azora",
|
||||
"sourceSite": "https://azorago.com/",
|
||||
"sourceSite": "https://azoramoon.com/",
|
||||
"sourceName": "Azora",
|
||||
"options": {
|
||||
"useNewChapterEndpoint": true,
|
||||
"lang": "Arabic"
|
||||
"lang": "Arabic",
|
||||
"versionIncrements": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -498,5 +502,14 @@
|
||||
"lang": "English",
|
||||
"useNewChapterEndpoint": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "fortuneeternal",
|
||||
"sourceSite": "https://fortuneeternal.com",
|
||||
"sourceName": "Fortune Eternal",
|
||||
"options": {
|
||||
"lang": "Korean",
|
||||
"useNewChapterEndpoint": true
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -14,6 +14,7 @@ type MadaraOptions = {
|
||||
lang?: string;
|
||||
orderBy?: string;
|
||||
versionIncrements?: number;
|
||||
customJs?: string;
|
||||
};
|
||||
|
||||
export type MadaraMetadata = {
|
||||
@@ -45,40 +46,27 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
|
||||
translateDragontea(text: Cheerio<AnyNode>): Cheerio<AnyNode> {
|
||||
if (this.id === 'dragontea') {
|
||||
const $ = parseHTML(text.html() || '');
|
||||
let sanitizedText = $.html() || '';
|
||||
sanitizedText = sanitizedText.replace('\n', '');
|
||||
sanitizedText = sanitizedText.replace(/<br\s*\/?>/g, '\n');
|
||||
text.html(sanitizedText);
|
||||
text.find(':not(:has(*))').each((i, el) => {
|
||||
// Select only the deepest elements to avoid reversing the text twice
|
||||
const $el = $(el);
|
||||
const alphabet =
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||
const reversedAlphabet =
|
||||
'zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA'.split('');
|
||||
const text = $el.text().normalize('NFD'); // Normalize the string to separate the accents
|
||||
const reversedText = text.split('');
|
||||
const reversedLetters = [...reversedText]
|
||||
.map(letter => {
|
||||
const baseLetter = letter.normalize('NFC');
|
||||
const index = alphabet.indexOf(baseLetter);
|
||||
return index !== -1
|
||||
? reversedAlphabet[index] + letter.slice(baseLetter.length)
|
||||
: letter;
|
||||
})
|
||||
.join('');
|
||||
$el.html(
|
||||
$el
|
||||
.html()
|
||||
?.replace($el.text(), reversedLetters)
|
||||
.replace('\n', '<br>') || '',
|
||||
);
|
||||
});
|
||||
}
|
||||
if (this.id !== 'dragontea') return text;
|
||||
|
||||
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>'));
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
getHostname(url: string): string {
|
||||
url = url.split('/')[2];
|
||||
@@ -258,6 +246,7 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
if (this.options?.useNewChapterEndpoint) {
|
||||
html = await fetchApi(this.site + novelPath + 'ajax/chapters/', {
|
||||
method: 'POST',
|
||||
referrer: this.site + novelPath
|
||||
}).then(res => res.text());
|
||||
} else {
|
||||
const novelId =
|
||||
@@ -318,10 +307,15 @@ class MadaraPlugin implements Plugin.PluginBase {
|
||||
loadedCheerio('.entry-content') ||
|
||||
loadedCheerio('.c-blog-post > div > div:nth-child(2)');
|
||||
|
||||
if (this.id === 'riwyat') {
|
||||
chapterText.find('span[style*="opacity: 0; position: fixed;"]').remove();
|
||||
if (this.options?.customJs) {
|
||||
try {
|
||||
// CustomJS HERE
|
||||
} catch (error) {
|
||||
console.error('Error executing customJs:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
chapterText.find('div.text-right').attr('style', 'text-align: right;');
|
||||
|
||||
return this.translateDragontea(chapterText).html() || '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user