diff --git a/public/static/multisrc/madara/fortuneeternal/icon.png b/public/static/multisrc/madara/fortuneeternal/icon.png new file mode 100644 index 0000000..52fe996 Binary files /dev/null and b/public/static/multisrc/madara/fortuneeternal/icon.png differ diff --git a/scripts/multisrc/madara/README.md b/scripts/multisrc/madara/README.md index 0854e9f..4fe34af 100644 --- a/scripts/multisrc/madara/README.md +++ b/scripts/multisrc/madara/README.md @@ -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 diff --git a/scripts/multisrc/madara/generator.js b/scripts/multisrc/madara/generator.js index 4365687..a570619 100644 --- a/scripts/multisrc/madara/generator.js +++ b/scripts/multisrc/madara/generator.js @@ -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(); diff --git a/scripts/multisrc/madara/sources.json b/scripts/multisrc/madara/sources.json index 4718d36..0b1bef8 100644 --- a/scripts/multisrc/madara/sources.json +++ b/scripts/multisrc/madara/sources.json @@ -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 + } } ] \ No newline at end of file diff --git a/scripts/multisrc/madara/template.ts b/scripts/multisrc/madara/template.ts index c3a457c..74a4b09 100644 --- a/scripts/multisrc/madara/template.ts +++ b/scripts/multisrc/madara/template.ts @@ -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): Cheerio { - if (this.id === 'dragontea') { - const $ = parseHTML(text.html() || ''); - let sanitizedText = $.html() || ''; - sanitizedText = sanitizedText.replace('\n', ''); - sanitizedText = sanitizedText.replace(//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', '
') || '', - ); - }); - } + if (this.id !== 'dragontea') return text; + + const $ = parseHTML(text.html()?.replace('\n', '').replace(//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', '
')); + }); + 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() || ''; }