Skip to content

Instantly share code, notes, and snippets.

@leobm
Last active July 29, 2021 10:33
Show Gist options
  • Save leobm/6388710fa6c96b6ae1fa783015209e10 to your computer and use it in GitHub Desktop.
Save leobm/6388710fa6c96b6ae1fa783015209e10 to your computer and use it in GitHub Desktop.
Delete youtube comments activity
// ==UserScript==
// @name Delete youtube comments activity
// @version 1
// @grant none
// @include https://myactivity.google.com/page*
// ==/UserScript==
const DELETE_MAX_ENTRIES_AFTER_PAGE_RELOAD = 1;
(function(d) {
if (/\bpage=youtube_comments\b/.test(location.search)) {
var deleteButtons = [];
var youtubeImgs = query(d, 'img[src="https://www.gstatic.com/images/branding/product/2x/youtube_24dp.png"]');
for (var i=0, max=youtubeImgs.length; i < max; i++) {
var btnContainer = youtubeImgs[i].parentNode.parentNode.parentNode;
var deleteButton = query(btnContainer, 'button')[0];
deleteButtons.push(deleteButton);
}
for (var i=0; i < DELETE_MAX_ENTRIES_AFTER_PAGE_RELOAD; i++){
deleteButtons[i].click();
}
}
function query(startNode, selector) {
try {
var nodes = Array.prototype.slice.call(
startNode.querySelectorAll(selector));
return nodes;
} catch(e){}
return [];
}
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment