Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alpersilistre/a37d273846105307b5416f4ea6a3f3e9 to your computer and use it in GitHub Desktop.
Save alpersilistre/a37d273846105307b5416f4ea6a3f3e9 to your computer and use it in GitHub Desktop.
This script can be run on the https://hn.tigran.io/post/xxxxxxx page to add Hide buttons to all main comments in the screen. I can hide them by clicking the 'Hide' button to lessen the noise after I read any root comment.
// works on https://hn.tigran.io/post/xxxxxxx page
let parentComments = document.querySelector('main > div').querySelectorAll(':scope > div');
function createHideItem() {
let span = document.createElement('span');
span.textContent = 'Hide';
span.addEventListener('click', x => {
console.log(x);
x.target.parentNode.parentNode.style.display = 'none';
});
return span;
}
parentComments.forEach(x => {
x.firstChild.appendChild(createHideItem());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment