(async () => {
console.log('Grabbing Statuses.');
let _token = JSON.parse(localStorage.getItem("oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-stable")).access_token;
let statusRes = (await (await fetch("https://api.mangadex.org/manga/status",{headers:{Authorization:"Bearer "+_token}})).json());
let statuses = Object.keys(statusRes.statuses);
await new Promise((rs)=>{setTimeout(rs,200)});
console.log('Grabbing Follows:\n ');
let _offset, _resTotal;
_offset = _resTotal = 0;
let follows = [];
do{
let rls = Date.now();
let res = (await (await fetch("https://api.mangadex.org/user/follows/manga?limit=100&offset="+_offset,{headers:{Authorization:"Bearer "+_token}})).json());
_resTotal = res.total;
follows.push(...res.data.map(m => m.id))
_offset += 100;
console.log('Follows %o/%o',Math.min(_offset,_resTotal),_resTotal)
if(res.data.length == 0) _offset++;
let rld = Date.now() - rls;
if(rld < 200) await new Promise((rs)=>{setTimeout(rs,200-rld)});
}while(_resTotal - _offset > 0)
console.log(' ')
let diff = follows.filter(id => !statuses.includes(id));
console.log("Statuses: %o Follows: %o/%o (%o deleted entries?) Bugged Statuses: %o",statuses.length,follows.length,_resTotal,_resTotal-follows.length,diff.length);
if(diff.length > 0){
console.log("\n"+(diff.map(id => "https://mangadex.org/title/"+id).join('\n'))+'\n\nAttemping to set as Reading.\n ');
for(let uuid of diff){
let rls = Date.now();
let res = (await fetch("https://api.mangadex.org/manga/"+uuid+"/status",{method: "POST", headers:{"Content-Type": "application/json", Authorization:"Bearer "+_token}, body: JSON.stringify({status:'reading'})}));
console.log('*POST* for %s returned %o %s',uuid,res.status,(res.status==200)?'Fixed!':'Not Fixed.')
let rld = Date.now() - rls;
if(rld < 200) await new Promise((rs)=>{setTimeout(rs,200-rld)});
}
console.log('\nDone!')
}
})()