/*
A script to delete all videos from a Tittok account
Learn how to delete all TikTok videos programmatically with this JavaScript script.
This script triggers hover events, clicks "Delete" buttons, and automates the video deletion process.
1. go to your latest video and paste this entire script in the terminal.
2. wait until all videos are deleted one by one
This script will programatically click the delete button on your videos one by one.
*/
function triggerHoverEvent(element) {
const hoverEvent = new MouseEvent('mouseover', {
bubbles: true,
cancelable: true,
view: window,
});
element.dispatchEvent(hoverEvent);
}
function clickDeleteButtonInLI() {
const liElements = document.querySelectorAll('li[data-e2e="video-delete"]');
for (const liElement of liElements) {
const deleteButton = liElement.querySelector('button');
if (deleteButton && deleteButton.textContent.trim() === 'Delete') {
deleteButton.click();
setTimeout(() => {
const modalDeleteButton = document.querySelector('[data-e2e="video-modal-delete"]');
if (modalDeleteButton) {
modalDeleteButton.click();
}
}, 200); // Wait 200 milliseconds after clicking "Delete" button
return; // Exit the loop after the first successful click
}
}
}
function performVideoDeletion() {
const targetElement = document.querySelector('[data-e2e="video-setting"]');
if (targetElement) {
triggerHoverEvent(targetElement);
setTimeout(clickDeleteButtonInLI, 2000); // Adjust the initial delay as needed (2 seconds in this case)
setTimeout(() => {
performVideoDeletion(); // Recursively call the function after a 3-second delay
}, 3000); // Wait 3 seconds before performing the next operation
} else {
console.log("No more elements found. Stopping.");
}
}
// Start the process
performVideoDeletion();