Skip to content

Instantly share code, notes, and snippets.

@DealsBeam
Forked from cprima/README.md
Created September 11, 2023 11:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DealsBeam/71bc0e5d0e9091146b3d39dbabde7836 to your computer and use it in GitHub Desktop.
Save DealsBeam/71bc0e5d0e9091146b3d39dbabde7836 to your computer and use it in GitHub Desktop.
Google MyActivity YouTube Comment Delete Script πŸ’¬βŒ

CommentCleanser for YouTube πŸ’¬βŒ

Description

Looking to take control of your digital history? CommentCleanser for YouTube lets you efficiently delete old YouTube comments from Google's MyActivity. Prioritize the removal of older comments, ensuring a leaner digital footprint and a conscious cleanup of your online history.

The script has been designed for users who have a significant number of YouTube comments and wish to delete them in bulk from Google's MyActivity page. By leveraging JavaScript, it provides a means to automate the process of deleting individual comments, offering the user control over how many comments to delete at once.

In today's rapidly changing social landscape, the words and sentiments we once casually expressed can come back to haunt us. What might have been a mere fleeting thought or a commonly held belief a few years ago, can now be viewed as socially unacceptable, casting shadows over one's character. The danger isn't just virtual; these old comments can pose genuine threats to employment opportunities, social standing, and overall well-being. The digital footprint we've left over the years is more than just a record; it's an open book, judged by today's standards, with real consequences in our day-to-day lives.

Compatibility

The script has been tested on 2023-09-02 and found compatible with the following browsers:

  • Edge version 116.0.1938.62 (Official build) (64-bit)
  • Chrome version 116.0.5845.141 (Official Build) (64-bit)
  • Firefox version 117.0 (64-bit)

Features

  • Selective Deletion: You can choose to delete a specific number of comments or all of them.
  • Bottom-Up Approach: Deletes comments starting from the oldest.
  • Highlight Before Deletion: For clarity, the script highlights a comment right before deletion.
  • User Control: You have the choice to specify the exact number of comments you wish to delete or can decide to delete all comments. The script will prompt you at each step.

Usage

  1. Navigate to MyActivity YouTube Comments page. Use exactly this link, as it will ensure that the script is able to find the comments.
  2. Open your browser's developer console.
  3. Copy-paste the provided script.
  4. Follow the on-screen prompts to execute deletions.

Safety and Control

If you wish to halt the script:

  • Click 'cancel' when prompted.
  • Or simply close the browser tab.

However, always be cautious: once a comment is deleted, it is irreversible.

Reporting Issues

If you encounter any issues or have suggestions for improvement, please report them as a comment to the gist.

License

This project is licensed under the MIT License.

Author

Christian Prior-Mamulyan

Source

The script can be found at this gist.


Note: Please use this script responsibly and understand that any deletion is permanent.


Basement filled with balloons representing YouTube comments

In the shadowy basement of digital history, balloons symbolizing long-forgotten YouTube comments drift aimlessly. As rays of sunlight try to pierce through the solitary window, hinting at the possibility of a cleaner digital slate, a watchful teddy bear stands guard. Yet, lurking in the dark corners, unseen entities await, ready to pounce upon any overlooked comment, emphasizing the peril of neglecting our online past.
/**
* Google MyActivity YouTube Comment Deletion Script
*
* Script to assist in bulk deletion of YouTube comments from Google's MyActivity.
*
* Usage:
* - Navigate to MyActivity YouTube Comments page.
* - Open browser's developer console.
* - Copy-paste this script, and follow on-screen prompts.
*
* Features:
* - Deletes comments from bottom (oldest first).
* - User control: specify number to delete, or cancel anytime.
*
* Safety:
* - Halting: 'cancel' during prompt or close tab.
*
* Author: Christian Prior-Mamulyan
* License: MIT
* Source: https://gist.github.com/cprima/2f7ea8e353c18a666506021c85e9773d
*
* Use cautiously. Deletion is irreversible.
*/
function navigateToCommentActivityPage() {
const desiredURL = "https://myactivity.google.com/page?hl=en&utm_medium=web&utm_source=youtube&page=youtube_comments";
console.warn("The function 'navigateToCommentActivityPage' is deprecated. Please use ensureOnCorrectActivityPage().");
if (window.location.href !== desiredURL) {
window.location.href = desiredURL;
return false;
}
return true;
}
function ensureOnCorrectActivityPage() {
const elementsData = [
{
url: "https://myactivity.google.com/page?hl=en&utm_medium=web&utm_source=youtube&page=youtube_comments",
content: "Your YouTube comments"
},
{
url: "https://myactivity.google.com/page?hl=en&utm_medium=web&utm_source=youtube&page=youtube_live_chat",
content: "Your YouTube live chat messages"
},
{
url: "https://myactivity.google.com/page?hl=en&utm_medium=web&utm_source=youtube&page=youtube_comment_likes",
content: "Your Likes and Dislikes on YouTube Comments"
}
];
const currentUrl = window.location.href;
const elementsWithClass = Array.from(document.querySelectorAll('.jPCT6'));
for (let elementData of elementsData) {
if (currentUrl.startsWith(elementData.url)) {
if (elementsWithClass.some(el => el.textContent.toLowerCase().includes(elementData.content.toLowerCase()))) {
console.log(`Matched URL: ${elementData.url} with content: "${elementData.content}"`);
return true; // Matched desired URL with corresponding content.
}
}
}
console.log(`You are not on a recognized page. Please navigate to: ${elementsData[0].url}`);
return false;
}
async function scrollToBottom() {
while (!document.evaluate('//div[contains(text(), "Looks like you\'ve reached the end")]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) {
window.scrollTo(0, document.body.scrollHeight);
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
function highlightElement(el) {
el.style.backgroundColor = '#ffcccb'; // Light red
setTimeout(() => {
el.style.backgroundColor = ''; // Reset background color after 1s
}, 1000);
}
function determineBestSelector() {
const SELECTORS = [
'.VfPpkd-Bz112c-LgbsSe.yHy1rc.eT1oJ.mN1ivc',
'[aria-label^="Delete activity item"]',
'[jscontroller="soHxf"]'
];
// Get the selector that matches the least amount of elements (more specific)
SELECTORS.sort((a, b) => document.querySelectorAll(a).length - document.querySelectorAll(b).length);
return SELECTORS[0];
}
let deleteButtons = [];
async function deleteComments(deleteBatchSize) {
const bestSelector = determineBestSelector();
if (!deleteButtons.length) {
deleteButtons = [...document.querySelectorAll(bestSelector)]; //.reverse();
}
let count = 0;
while (deleteButtons.length && (count < deleteBatchSize || deleteBatchSize === Infinity)) {
const btn = deleteButtons.pop();
// Scroll to the button to make it visible before deletion
btn.scrollIntoView({
behavior: 'smooth',
block: 'center'
});
await new Promise(resolve => setTimeout(resolve, 1000)); // Give a moment for the scroll to finish
highlightElement(btn);
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for 2s for the highlight to be visible
btn.click();
count++;
await new Promise(resolve => setTimeout(resolve, 1500));
}
return deleteButtons.length; // Return the number of remaining comments
}
async function initiateCommentDeletion() {
// if (!navigateToCommentActivityPage()) {
// return;
// }
if (!ensureOnCorrectActivityPage()) {
return;
}
await scrollToBottom();
const bestSelector = determineBestSelector();
const totalComments = document.querySelectorAll(bestSelector).length;
if (!totalComments) {
console.log("No comments found for deletion.");
return;
}
let userInput = prompt(`Found ${totalComments} comments. Enter 'a' to delete all comments or input a number to delete that many comments. Press 'Cancel' at any time to stop the script:`);
while (userInput !== null) {
if (userInput.toLowerCase() === 'a') {
await deleteComments(Infinity);
console.log("All comments deleted.");
return;
} else if (!isNaN(parseInt(userInput))) {
const deleteBatchSize = parseInt(userInput);
const remainingComments = await deleteComments(deleteBatchSize);
if (!remainingComments) {
console.log("All comments deleted.");
return;
}
userInput = prompt(`${remainingComments} comments remaining. Enter 'a' to delete all remaining comments or input a number to delete that many comments. Press 'Cancel' at any time to stop the script:`);
} else {
userInput = prompt("Invalid input. Please enter 'a' or a number:");
}
}
console.log("Operation canceled. No further comments will be deleted.");
}
initiateCommentDeletion();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment