// ==UserScript==
// @name MangaDex Follows
// @namespace https://greasyfork.org/es/scripts/411685-mangadex-follows
// @version 1.3.3
// @description Manage your follows page
// @author Australis
// @match https://mangadex.org/follows*
// @grant none
// ==/UserScript==
console.log("Executing");
let blacklist = [
// [23811,657],
// [23811,12]
]
let whitelist = [
// [23811,3043],
// [22843,12672]
]
checker = []
function Checker(node){
if(checker.length == 0) checker = [node]
else checker.push(node)
console.log(node)
}
function CleanChecker(id){
try{
for(var x=checker.length-1; x>=0; x--){
if(checker[x][0] == id) checker.splice(x,1)
}
}catch(e){
checker = []
}
}
function Ahead(){
if(checker.length){
for(c of checker){
c[1].getElementsByClassName("chapter_mark_read_button grey")[0].setAttribute("class","chapter_mark_read_button")
c[1].getElementsByClassName("chapter_mark_read_button")[0].setAttribute("style","color: red")
}
}
checker = []
}
function FindSeries(array, number){
for(var i=0; i < array.length; i++){
if(array[i][0]*1 == number*1) return i;
}
return -1;
}
try{
series = JSON.parse(localStorage.getItem('series'))
}catch(e){
series = []
console.log("failed to retrieve series")
}
//add titles from follows
if(document.URL.includes('mangadex.org/follows/manga')){
series_col = document.getElementsByClassName("manga-entry border-bottom");
for(var s of series_col){
var row = s.getElementsByClassName("row m-0")[1];
var name = row.children[0].innerText;
var state = row.children[2].innerText;
var id = s.dataset.id;
var node = [id,name,state,0]
var add = true;
if(series){
for(var m of series){
if(m[0] === id){
add = false;
if(m[2] !== state) m[2] = state;
}
}
if(add) series.push(node);
}
else series = [node]
}
localStorage.setItem('series',JSON.stringify(series))
}
else if(document.URL.includes('mangadex.org/follows')){
//read chapters
row = document.getElementsByClassName("chapter-container")[0].children;
// row[0].remove()
function Hide(DataSet){
for(var b of blacklist){
if(b[0] == DataSet.mangaId && b[1] == DataSet.group) return true
}
return false
}
function OnlyThis(DataSet){
for(var w of whitelist){
if(w[0] == DataSet.mangaId && w[1] != DataSet.group) return 0
if(w[0] == DataSet.mangaId && w[1] == DataSet.group) return 1
}
return 2
}
changeH = false
changeO = false
for(var r of row){
dataset = r.children[2].childNodes[1].dataset;
if(dataset.mangaId){
manga_id = dataset.mangaId;
try{//arreglar
if(Hide(dataset)) {
title = r.children[0].innerHTML
r.setAttribute("style","display: none")
changeH = true
}
else if(changeH){
title2 = r.children[0].innerHTML
if(r.children[0].classList.contains("d-md-flex")) r.children[0].innerHTML = title
title = title2
changeH = false
}
if(!OnlyThis(dataset)) {
title = r.children[0].innerHTML
r.setAttribute("style","display: none")
changeO = true
}
else if(changeO){
title2 = r.children[0].innerHTML
if(r.children[0].classList.contains("d-md-flex")) r.children[0].innerHTML = title
title = title2
changeO = false
}
}catch(e){}
try{
if(r.innerHTML.includes("mark_unread")){
if(series[FindSeries(series,manga_id)][3]*1 < dataset.chapter*1) series[FindSeries(series,manga_id)][3] = dataset.chapter*1;
}
else if(series[FindSeries(series,manga_id)][3]*1 >= dataset.chapter*1){ //a duplicate
r.getElementsByClassName("chapter_mark_read_button grey")[0].setAttribute("class","chapter_mark_read_button")
r.getElementsByClassName("chapter_mark_read_button")[0].setAttribute("style","color: blue")
}
else{//a new one
if(series[FindSeries(series,manga_id)][3]*1 != 0
&& series[FindSeries(series,manga_id)][3]*1 < dataset.chapter*1+1){//skipped chapter
// console.log("current: "+dataset.chapter)
// console.log("last: "+series[FindSeries(series,manga_id)][3])
Checker([manga_id,r])
}
if(series[FindSeries(series,manga_id)][3]*1 < dataset.chapter*1
&& dataset.chapter*1 <= series[FindSeries(series,manga_id)][3]*1+1){//next chapter
CleanChecker(manga_id)
}
}
}catch(e){
//series not included
console.log(dataset.mangaId+" "+r.children[0].innerText)
series.push([dataset.mangaId,r.children[0].innerText,' Reading',0])
}
}//end if
}//end for
Ahead()
localStorage.setItem('series',JSON.stringify(series))
}
if(document.URL.includes('mangadex.org/title/')){
var follow_stat = document.getElementsByClassName("btn-group")[0].childNodes[0].childNodes[0].className;
if(follow_stat.includes("fa-eye") || follow_stat.includes("fa-check")){
var temp = document.getElementsByClassName("chapter-row d-flex row no-gutters p-2 align-items-center border-bottom odd-row");
for(var t of temp){
if(t.dataset != null){
dataset = t.dataset;
manga_id = dataset.mangaId;
if(t.innerHTML.includes("mark_unread")) {
if(series[FindSeries(series,manga_id)][3]*1 < dataset.chapter*1) series[FindSeries(series,manga_id)][3] = dataset.chapter*1;
}
}
}
localStorage.setItem('series',JSON.stringify(series))
console.log("OK");
}
}
if(document.URL.includes('mangadex.org/follows') && !document.URL.includes('mangadex.org/follows/manga')){
let data = [['ID','Series name','Status','Last Read']].concat(series);
for(var d of data){
if(d[1].includes("\"")) d[1] = d[1].replaceAll("\"","|")
if(d[1].includes(";")) d[1] = d[1].replaceAll(";",":")
}
// Building the CSV from the Data two-dimensional array
// Each column is separated by ";" and new line "\n" for next row
let csvContent = '';
data.forEach(function(infoArray, index) {
dataString = infoArray.join(';');
csvContent += index < data.length ? dataString + '\n' : dataString;
});
// The download function takes a CSV string, the filename and mimeType as parameters
// Scroll/look down at the bottom of this snippet to see how download is called
let download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) { // IE10
navigator.msSaveBlob(new Blob([content], {
type: mimeType
}), fileName);
} else if (URL && 'download' in a) { //html5 A[download]
a.href = URL.createObjectURL(new Blob([content], {
type: mimeType
}));
a.setAttribute('download', fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported
}
}
window.download = function(){download(csvContent, 'MangaDex.csv', 'text/csv;encoding:utf-8')}
let boton = document.createElement("li")
boton.setAttribute("class","nav-item")
boton.setAttribute("href","#")
boton.setAttribute("onclick","download()")
boton.appendChild(document.createElement("a"))
boton.children[0].setAttribute("class","nav-link")
boton.children[0].appendChild(document.createElement("span"))
boton.children[0].children[0].setAttribute("class","fas fa-download fa-fw")
boton.children[0].children[0].setAttribute("aria-hidden","true")
boton.children[0].appendChild(document.createElement("span"))
boton.children[0].children[1].setAttribute("class","d-none d-md-inline")
boton.children[0].children[1].innerText = "Export"
document.getElementsByClassName("nav nav-tabs")[0].insertBefore(boton,document.getElementsByClassName("nav nav-tabs")[0].children[4])
}