-
-
Save alok-mishra/405963a24599b16280f9a535da89133b to your computer and use it in GitHub Desktop.
// Removes all items from a page of the Trakt collection | |
// Run script from console of user's collection page | |
// Must be run on each page | |
$(".posters .grid-item").each(function() { | |
actionWatch($(this).closest('.grid-item'), 'collect', true) | |
}) |
The problem with the last version of the snippet is that you have to run it multiple times because it always skips some entries.
Example: There are 100 entries in total and 30 are on each page.
- The first 30 are deleted, 3 pages are left
- The algorithm jumps to the 2nd page, which shows entries 30-59 out of the remaining 70
- Entries 30-59 are deleted, the algorithm jumps to the 3rd page
- There are only 40 entries left, so there is no 3rd page, the user has to jump back to page 1 and start again.
The number of times the user has to jump to page 1 and restart is log2(totalPages)
. So for 1000 pages that's 10 times.
It would be better if the algorithm alternated between going one page forward and one page back.
My untested proposed solution:
let goForward = true;
function wipePage() {
$(".grid-item").each( function( index) {
actionWatch($(this), "collect", true)
});
if (goForward) {
$(".pagination-top .pagination .next a")[0].click();
}
else {
$(".pagination-top .pagination .prev a")[0].click();
}
goForward = !goForward;
setTimeout(wipePage, 4000);
}
wipePage();
@reconman, your solution seems to work, but I had two issues (none of which is caused by your solution);
- Trakt seems to have some horrible caching in place, causing deleted items to show up randomly, and number of pages change between different cached versions (if you started off at 100 pages, after deleting some, you're down at 80, then back at 100, then down to 90, up to 95, back to 75, etc). This causes lot's of attempts to remove already removed stuff (and also lots of 400 response codes).
- Trakt have their page behind Cloudflare, which seems to give 502 responses from the backend after a while. Most likely caused by some kind of rate limiting. Have to stop, wait, and then re-apply.
Create a bookmark with the following saved as url. Makes it much easier to just select the bookmark once it switches pages. Following reconman suggestion:
javascript:function wipePage() {
$(".grid-item").each(function(index) {
actionWatch($(this), "collect", true);
});
if (localStorage.getItem('goForward') === "true") {
$(".pagination-top .pagination .next a")[0].click();
alert("Page cleared. Navigate to the next page and click the bookmarklet again.");
localStorage.setItem('goForward', "false");
} else {
$(".pagination-top .pagination .prev a")[0].click();
alert("Page cleared. Navigate to the previous page and click the bookmarklet again.");
localStorage.setItem('goForward', "true");
}
}
wipePage();
@EverAndy, this works
Thank you!
The solutions worked fine until very recently. Trakt throwing up "Doh!" errors when trying to run this.
The solutions worked fine until very recently. Trakt throwing up "Doh!" errors when trying to run this.
I confirm that the server responds with a Too many requests
error. Due to this, I wrote the following script to clear my collection page by page. 32 pages in my case. Have fun.
function clearCollect(time = 2000) {
var i = 0, items = $(".grid-item");
console.log(`Start remove ${items.length} items`);
var interval = setInterval(() => {
if (i < items.length) {
let item = $(items[i++]);
actionWatch(item, "collect", true);
console.log(`Remove item ${i - 1}`);
} else clearInterval(interval);
}, time);
}
clearCollect();
@Clndl Your version works perfectly with the new rate limiting. You can decrease the interval to 1500ms without hitting the limit though.
I hit limits with 1500ms. Here's a version that works and integrates pagination again: gist link
const RATE_LIMIT_DELAY = 2000; // Delay between each item collection (2 seconds)
const PAGE_CHANGE_DELAY = 5000; // Delay before changing page (5 seconds)
async function clearTraktCollection() {
// Collect current page
const items = $(".grid-item");
console.log(`Processing ${items.length} items on current page`);
// Process items one by one with delay
for (let i = 0; i < items.length; i++) {
const item = $(items[i]);
actionWatch(item, "collect", true);
console.log(`Removed item ${i + 1}/${items.length}`);
await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_DELAY));
}
// Check if there's a next page
const nextPageButton = $(".pagination-top .page.active").next().find('a');
if (nextPageButton.length) {
console.log("Moving to next page...");
await new Promise(resolve => setTimeout(resolve, PAGE_CHANGE_DELAY));
nextPageButton[0].click();
// Wait for page load and continue collection
setTimeout(clearTraktCollection, PAGE_CHANGE_DELAY);
} else {
console.log("Collection cleared - no more pages");
}
}
// Start the clearing process
clearTraktCollection();
I hit limits with 1500ms. Here's a version that works and integrates pagination again: gist link
const RATE_LIMIT_DELAY = 2000; // Delay between each item collection (2 seconds) const PAGE_CHANGE_DELAY = 5000; // Delay before changing page (5 seconds) async function clearTraktCollection() { // Collect current page const items = $(".grid-item"); console.log(`Processing ${items.length} items on current page`); // Process items one by one with delay for (let i = 0; i < items.length; i++) { const item = $(items[i]); actionWatch(item, "collect", true); console.log(`Removed item ${i + 1}/${items.length}`); await new Promise(resolve => setTimeout(resolve, RATE_LIMIT_DELAY)); } // Check if there's a next page const nextPageButton = $(".pagination-top .page.active").next().find('a'); if (nextPageButton.length) { console.log("Moving to next page..."); await new Promise(resolve => setTimeout(resolve, PAGE_CHANGE_DELAY)); nextPageButton[0].click(); // Wait for page load and continue collection setTimeout(clearTraktCollection, PAGE_CHANGE_DELAY); } else { console.log("Collection cleared - no more pages"); } } // Start the clearing process clearTraktCollection();
I get a Doh! error even with this for some reason, but the one from Clndl works
Anyways, thanks everyone for the help with this. No clue why this isn't easier
For those who needs to remove the items of watchlist, just replace
collect
withwatchlist
of @luehm's snippet.