Danbooru

How to delete all favorites?

Posted under General

XestroSin4 said:

Could someone give me a script that would allow me to delete every single one of my favorites? Please and thank you. I would try to create one myself but coding isn't my area of expertise.

Use the search fav:XestroSin4 and switch the Mode below the search bar to "Unfavorite", and then click through all of your favorites until they're deleted. Starting from the end and working forward works better due to how pagination and searches work.

BrokenEagle98 said:

Use the search fav:XestroSin4 and switch the Mode below the search bar to "Unfavorite", and then click through all of your favorites until they're deleted. Starting from the end and working forward works better due to how pagination and searches work.

He has 25k favorites so that's not very practical.

XestroSin4 said:

Could someone give me a script that would allow me to delete every single one of my favorites? Please and thank you. I would try to create one myself but coding isn't my area of expertise.

I could write something for you, but you’d need a Linux command line to run it. If you don’t have that available, I could run it for you, but I’d need your API key for it.

Note: Giving someone your API key is like giving them your password. I’m only suggesting this because you seem to have pretty much nothing on your account besides the favorites you want to delete. Only give me your API key if you don’t mind me seeing your favorites. I can delete them without seeing them and I’m not actually interested in seeing them, but you don’t know that. ;) You’d also have to regenerate your API key once I’m done to lock me out again. If you’re interested, send me a DM. I’d take the little code challenge.

BrokenEagle98 said:

Use the search fav:XestroSin4 and switch the Mode below the search bar to "Unfavorite", and then click through all of your favorites until they're deleted. Starting from the end and working forward works better due to how pagination and searches work.

nonamethanks said:

He has 25k favorites so that's not very practical.

Yeah, I tried that for a bit but then I gave up as its not time efficient. Thanks for the replies though.

kittey said:

I could write something for you, but you’d need a Linux command line to run it. If you don’t have that available, I could run it for you, but I’d need your API key for it.

Note: Giving someone your API key is like giving them your password. I’m only suggesting this because you seem to have pretty much nothing on your account besides the favorites you want to delete. Only give me your API key if you don’t mind me seeing your favorites. I can delete them without seeing them and I’m not actually interested in seeing them, but you don’t know that. ;) You’d also have to regenerate your API key once I’m done to lock me out again. If you’re interested, send me a DM. I’d take the little code challenge.

DM sent!

Copied and adjusted the following from topic #13383.

(async function (user_id) {
    page = 0;
    iteration = 1;
    while (true) {
        favorites = await $.getJSON('/favorites.json',{search:{user_id:user_id},limit:200,page:'a'+page,only:'id,post_id'});
        console.log(`Batch #${iteration++}: Deleting ${favorites.length} favorites.`);
        for(i=0;i<favorites.length;i++) {
            try {
                await $.post(`/favorites/${favorites[i].post_id}.json`,{_method:'delete'});
            } catch(e) {
                console.warn('post #'+favorites[i].post_id,e?.status,e?.responseText);
            }
        }
        if (favorites.length<200) {
            break;
        }
        page=favorites[0].id;
    }
    Danbooru.Utility.notice('Done deleting favorites.');
})(Danbooru.CurrentUser.data('id'));

BrokenEagle98 said:

Copied and adjusted the following from topic #13383.

(async function (user_id) {
    page = 0;
    iteration = 1;
    while (true) {
        favorites = await $.getJSON('/favorites.json',{search:{user_id:user_id},limit:200,page:'a'+page,only:'id,post_id'});
        console.log(`Batch #${iteration++}: Deleting ${favorites.length} favorites.`);
        for(i=0;i<favorites.length;i++) {
            try {
                await $.post(`/favorites/${favorites[i].post_id}.json`,{_method:'delete'});
            } catch(e) {
                console.warn('post #'+favorites[i].post_id,e?.status,e?.responseText);
            }
        }
        if (favorites.length<200) {
            break;
        }
        page=favorites[0].id;
    }
    Danbooru.Utility.notice('Done deleting favorites.');
})(Danbooru.CurrentUser.data('id'));

Worked on my end! :D I appreciate all the responses here. This is such a helpful community.

1