add manga parser
This commit is contained in:
parent
7e4438abfb
commit
d5c9af7722
@ -6,38 +6,88 @@
|
||||
* 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) => {
|
||||
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);
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
data.forEach((i) => {
|
||||
exportArray.push(`* ${i.title} [${i.type}] [${i.epCurrent}/${i.epTotal}]`);
|
||||
});
|
||||
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');
|
||||
|
Loading…
Reference in New Issue
Block a user