Created
April 12, 2023 17:19
-
-
Save exbotanical/1ae8612e9754164f56e02e86661a6358 to your computer and use it in GitHub Desktop.
Remove ChatGPT Posts from HackerNews
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name New Userscript | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://news.ycombinator.com/*?\? | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com | |
// @grant none | |
// ==/UserScript== | |
// TODO: use Violentmonkey | |
;(function () { | |
'use strict' | |
cleanHackerNews() | |
})() | |
function cleanHackerNews() { | |
console.info('cleaning HackerNews...') | |
const ranks = document.querySelectorAll('span.rank') | |
let rankCount = ranks.item(0)?.innerHTML ?? 1 | |
const posts = document.querySelectorAll('tr.athing') | |
if (!posts) { | |
console.info('unable to select HackerNews posts; this is a bug') | |
return | |
} | |
posts.forEach(post => { | |
const title = post.querySelector('span.titleline > a') | |
if (!title) { | |
console.info('unable to select HackerNews title; this is probably a bug') | |
return | |
} | |
if (title.innerHTML.includes('GPT')) { | |
post.remove() | |
} | |
}) | |
posts.forEach(post => { | |
const rank = post.querySelector('span.rank') | |
if (!rank) { | |
console.info('unable to select HackerNews title; this is probably a bug') | |
return | |
} | |
rank.innerHTML = `${rankCount++}.` | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment