Skip to content

Instantly share code, notes, and snippets.

@surprisetalk
Created March 23, 2023 13:00
Show Gist options
  • Save surprisetalk/462789361723211fcda71e13fa08bbc0 to your computer and use it in GitHub Desktop.
Save surprisetalk/462789361723211fcda71e13fa08bbc0 to your computer and use it in GitHub Desktop.
Userscript to hide any HackerNews story with "GPT" in its title.
// ==UserScript==
// @name HackerNews GPT-Free Feed
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hides any Hacker News story with "GPT" in its title.
// @author Taylor Troesh
// @include https://news.ycombinator.com/*
// @grant none
// ==/UserScript==
[...document.getElementsByClassName("athing")].forEach(function(x) {
if(x.getElementsByClassName("titleline")[0].innerText.match(/gpt/i)) {
x.hidden = true;
x.nextElementSibling.hidden = true;
x.nextElementSibling.nextElementSibling = true;
}
});
@gabrielsroka
Copy link

gabrielsroka commented Mar 23, 2023

slightly shorter, using querySelectorAll and querySelector

document.querySelectorAll('.athing').forEach(el => {
  if (el.querySelector('.titleline').innerText.match(/gpt/i)) {
    el.hidden = true;
    el.nextElementSibling.hidden = true;
    el.nextElementSibling.nextElementSibling = true;
  }
});

also, is the last one supposed to have hidden too? so maybe

document.querySelectorAll('.athing').forEach(el => {
  if (el.querySelector('.titleline').innerText.match(/gpt/i)) {
    el.hidden = true;
    el.nextElementSibling.hidden = true;
    el.nextElementSibling.nextElementSibling.hidden = true;
  }
});

@mary-ext
Copy link

equivalent uBlock filter:

news.ycombinator.com##.athing:has(.titleline:has-text(/GPT/i))
news.ycombinator.com##.athing:has(.titleline:has-text(/GPT/i)) + tr
news.ycombinator.com##.athing:has(.titleline:has-text(/GPT/i)) + tr + tr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment