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