Skip to content

Instantly share code, notes, and snippets.

@chadlavi
Last active Jun 18, 2020
Embed
What would you like to do?
automatically click "hide" on ads in hackernews
// ==UserScript==
// @name No ads on HN
// @version 0.0.1
// @author Chad Lavimoniere
// @grant none
// @include https://news.ycombinator.com/*
// @downloadURL https://gist.github.com/chadlavi/888a0889dadf82a60ba0f32017a5e9cb/raw/no-ads-hn.user.js
// @updateURL https://gist.github.com/chadlavi/888a0889dadf82a60ba0f32017a5e9cb/raw/no-ads-hn.user.js
// ==/UserScript==
document.querySelectorAll('td.subtext').forEach(cell => {
const text = cell.innerText
// ads don't have points listed in their subtext lines, so any subtext
// line that doesn't contain the string "point" is proably an ad
if (!text.match(/point/)){
const links = cell.querySelectorAll('a')
links.forEach(link => {
if (link.innerText === 'hide') {
console.log('clicking "hide" link')
link.click()
}
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment