Skip to content

Instantly share code, notes, and snippets.

@mitcdh
Last active February 2, 2025 14:36
Show Gist options
  • Save mitcdh/77ebc25d4a67d8a54040300a6f90ff75 to your computer and use it in GitHub Desktop.
Save mitcdh/77ebc25d4a67d8a54040300a6f90ff75 to your computer and use it in GitHub Desktop.
Paginated and rate limit aware Trakt collection clearer
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 are still items on the page
const remainingItems = $(".grid-item");
if (remainingItems.length > 0) {
console.log("Items still present, reloading page 1...");
await new Promise(resolve => setTimeout(resolve, PAGE_CHANGE_DELAY));
// Find and click the first page button
const firstPageButton = $(".pagination-top .page").first().find('a');
if (firstPageButton.length) {
firstPageButton[0].click();
// Wait for page load and continue collection
setTimeout(clearTraktCollection, PAGE_CHANGE_DELAY);
}
} else {
console.log("Collection cleared - no more items");
}
}
// Start the clearing process
clearTraktCollection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment