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,38 +6,88 @@
* url: https://git.a2s.su/iiiypuk/userScripts/src/branch/master/JavaScript/mal_parser.js * 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(); 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,
type: item.anime_media_type_string,
epCurrent: item.num_watched_episodes,
epTotal: item.anime_num_episodes,
};
dataItems.forEach((item) => { dataExport.push(itemData);
let itemData = { });
// title: (item.anime_title_eng.trim().length > 0) ? item.anime_title_eng.trim() : item.anime_title,
title: item.anime_title,
type: item.anime_media_type_string,
epCurrent: item.num_watched_episodes,
epTotal: item.anime_num_episodes,
};
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 * Export items by gemtext syntax
* @param {array} data - The anime data. * @param {array} data - The anime data.
* @param {string} type - The data type (a/m).
*/ */
function exportForGemini(data) { function exportForGemini(data, type) {
let exportArray = Array(); let exportArray = Array();
data.forEach((i) => { console.log(data);
exportArray.push(`* ${i.title} [${i.type}] [${i.epCurrent}/${i.epTotal}]`);
}); 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) => { exportArray.forEach((line) => {
console.log(line); console.log(line);
}); });
} }
console.log(dataExport); // Run
// exportForGemini(dataExport); 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');