async function GetLibrary(readingStatus) {
const baseUrl = 'https://api.mangadex.org';
const authToken = JSON.parse(localStorage.getItem('oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-stable')).access_token;
let fetchUrl = `${baseUrl}/manga/status`;
if(readingStatus !== '')
fetchUrl = `${fetchUrl}?status=${readingStatus}`
let response = await fetch(fetchUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`,
},
});
return await response.json();
}
async function UnfollowTitle(titleId) {
const baseUrl = 'https://api.mangadex.org';
const authToken = JSON.parse(localStorage.getItem('oidc.user:https://auth.mangadex.org/realms/mangadex:mangadex-frontend-stable')).access_token;
let response = await fetch(`${baseUrl}/manga/${titleId}/follow`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${authToken}`,
'accept': 'application/json',
},
});
const result = await response.json();
}
function Sleep(milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds))
}
(async () => {
//const readingStatus = 'reading';
//const readingStatus = 'plan_to_read';
//const readingStatus = 'on_hold';
const readingStatus = 'dropped';
//const readingStatus = 're_reading';
//const readingStatus = 'completed';
//const readingStatus = ''; // empty for all titles
const result = await GetLibrary(readingStatus);
for(const id in result.statuses) {
await UnfollowTitle(id);
await Sleep(300);
}
})();