Last active
May 6, 2023 03:51
-
-
Save cgt/e208412fc0442bbca262a23b4f754346 to your computer and use it in GitHub Desktop.
Remove AI news from HN
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 HN AI remover | |
// @version 1 | |
// @grant none | |
// @match https://news.ycombinator.com/ | |
// @match https://news.ycombinator.com/news | |
// @match https://news.ycombinator.com/?p=* | |
// @match https://news.ycombinator.com/news?p=* | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const targetWords = '(\\b(ChatGPT|GPT-?(3|3\.5|4|5)?|OpenAI|AI|LLM|LLaMA)\\b|A\\.I\\.)'; | |
const re = new RegExp(targetWords, 'i'); | |
const rows = document.querySelectorAll('tr'); | |
for (let i = 0; i < rows.length; i++) { | |
const row = rows[i]; | |
const anchor = row.querySelector('td.title span.titleline a'); | |
if (row.classList.contains("athing") && anchor && re.test(anchor.textContent)) { | |
console.log("Removing link: " + anchor.textContent); | |
// Remove the current row (tr.athing) | |
console.log("[" + anchor.textContent.slice(0,5) + "...] ", row); | |
row.remove(); | |
// Check if there's a next row (plain tr), and if so, remove it | |
if (i + 1 < rows.length) { | |
console.log("[" + anchor.textContent.slice(0,5) + "...] ", rows[i + 1]); | |
rows[i + 1].remove(); | |
} | |
// Check if there's another next row (tr.spacer), and if so, remove it | |
if (i + 2 < rows.length && rows[i + 2].classList.contains("spacer")) { | |
console.log("[" + anchor.textContent.slice(0,5) + "...] ", rows[i + 2]); | |
rows[i + 2].remove(); | |
} | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment