Skip to content

Instantly share code, notes, and snippets.

@slavinskiyboris
Last active July 8, 2024 07:13
Show Gist options
  • Save slavinskiyboris/5524dab697ab321b71ccb265d525e0b9 to your computer and use it in GitHub Desktop.
Save slavinskiyboris/5524dab697ab321b71ccb265d525e0b9 to your computer and use it in GitHub Desktop.
Makes all your videos in TikTok visible only to you recursively
/*
1. Open your latest video and paste this entire script into the console.
2. Wait until all the videos will be hidden one by one.
*/
function triggerHoverEvent(element) {
const hoverEvent = new MouseEvent("mouseover", {
bubbles: true,
cancelable: true,
view: window
});
element.dispatchEvent(hoverEvent);
}
function doneAndNextBtnClick() {
// Find the Done button on the popup
const modalDoneButton = document.querySelector('[data-e2e="video-setting-down"]');
if (modalDoneButton) {
modalDoneButton.click();
}
setTimeout(() => {
// Find the next button on the video layer
const nextVideoButton = document.querySelector('[data-e2e="arrow-right"]');
if (nextVideoButton) {
nextVideoButton.click();
// Wait for next video loading (3 seconds in this case) then call whole process recursively
setTimeout(performHidingContent, 3000);
}
}, 100);
}
function performHidingContentFlow() {
const liElements = document.querySelectorAll('li[data-e2e="video-privacy-settings"]');
for (const liElement of liElements) {
const chooseButton = liElement.querySelector("button");
if (chooseButton && chooseButton.textContent.trim() === "Privacy settings") {
chooseButton.click();
// Wait for popup appearance
setTimeout(() => {
// Find the dropdown entry point
const modalDropdownButton = document.querySelector('[data-e2e="video-setting-choose"]');
if (modalDropdownButton) {
const pElement = modalDropdownButton.querySelector("p");
// Check which parameter is currently selected. If it's "Only you", then we're skipping this video.
if (pElement && pElement.textContent.trim() === "Only you") {
doneAndNextBtnClick();
} else {
modalDropdownButton.click();
// Wait for dropdown list appearance
setTimeout(() => {
// Catch all items from dropdown list
const listContent = document.querySelectorAll('[data-e2e="video-watch-list"]');
listContent.forEach((li) => {
if (li.textContent.includes("Only you")) {
li.click();
doneAndNextBtnClick();
}
});
}, 200);
}
}
}, 200);
break; // Exit the loop after clicking on the Privacy Settings
}
}
}
function performHidingContent() {
const targetElement = document.querySelector('[data-e2e="video-setting"]');
if (targetElement) {
triggerHoverEvent(targetElement);
// Wait for three dots mouse hover animation
setTimeout(performHidingContentFlow, 200);
} else {
console.log("No more elements found. Stopping.");
}
}
// Start the process
performHidingContent();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment