94 lines
2.2 KiB
JavaScript
94 lines
2.2 KiB
JavaScript
/**
|
|
* MyAnimeList lists parser
|
|
* @author Alexander Popov <iiiypuk@fastmail.fm>
|
|
* @version 1.0.0
|
|
* @license Unlicense
|
|
* url: https://git.a2s.su/iiiypuk/userScripts/src/branch/master/JavaScript/mal_parser.js
|
|
*/
|
|
|
|
/**
|
|
* Parse Anime list
|
|
* @param {DOMElement} element - The anime JSON data.
|
|
*/
|
|
function parseAnime(element) {
|
|
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,
|
|
};
|
|
|
|
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, 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);
|
|
});
|
|
}
|
|
|
|
// 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');
|