add manga parser

This commit is contained in:
Alexander Popov 2023-05-01 12:42:12 +03:00
parent 7e4438abfb
commit d5c9af7722
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6

View File

@ -6,12 +6,14 @@
* url: https://git.a2s.su/iiiypuk/userScripts/src/branch/master/JavaScript/mal_parser.js
*/
let dataElement = document.getElementsByTagName('table');
let dataItems = JSON.parse(dataElement[0].dataset.items);
/**
* Parse Anime list
* @param {DOMElement} element - The anime JSON data.
*/
function parseAnime(element) {
let dataExport = Array();
let dataExport = Array();
dataItems.forEach((item) => {
element.forEach((item) => {
let itemData = {
// title: (item.anime_title_eng.trim().length > 0) ? item.anime_title_eng.trim() : item.anime_title,
title: item.anime_title,
@ -21,23 +23,71 @@ dataItems.forEach((item) => {
};
dataExport.push(itemData);
});
});
return dataExport;
}
/**
* Parse Manga list
* @param {DOMElement} element - The manga JSON data.
*/
function parseManga(element) {
let dataExport = Array();
element.forEach((item) => {
let itemData = {
// title: (item.manga_english.trim().length > 0) ? item.manga_english.trim() : item.manga_title,
title: item.manga_title,
chCurrent: item.num_read_chapters,
chTotal: item.manga_num_chapters,
vlCurrent: item.num_read_volumes,
vlTotal: item.manga_num_volumes,
};
dataExport.push(itemData);
});
return dataExport;
}
/**
* Export items by gemtext syntax
* @param {array} data - The anime data.
* @param {string} type - The data type (a/m).
*/
function exportForGemini(data) {
function exportForGemini(data, type) {
let exportArray = Array();
console.log(data);
switch (type) {
case 'a':
data.forEach((i) => {
exportArray.push(`* ${i.title} [${i.type}] [${i.epCurrent}/${i.epTotal}]`);
});
break;
case 'm':
data.forEach((i) => {
exportArray.push(
`* ${i.title} [${i.chCurrent}/${i.chTotal}] [${i.vlCurrent}/${i.vlTotal}]`
);
});
break;
}
exportArray.forEach((line) => {
console.log(line);
});
}
console.log(dataExport);
// exportForGemini(dataExport);
// Run
let dataElement = document.getElementsByTagName('table');
let dataItems = JSON.parse(dataElement[0].dataset.items);
console.log(parseAnime(dataItems));
// console.log(parseManga(dataItems));
// exportForGemini(parseAnime(dataItems), 'a');
// exportForGemini(parseManga(dataItems), 'm');