Skip to content

Instantly share code, notes, and snippets.

@surprisetalk
Created March 23, 2023 13:00
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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;
}
});
@jdwhite
Copy link

jdwhite commented Mar 23, 2023

Might need to add "Bard" to that match as well. :-/

@surprisetalk
Copy link
Author

You can update the regex to match any number of terms:

/(gpt|bard)/i

@OrionRandD
Copy link

Might need to add "Bard" to that match as well. :-/

and https://you.com

@louis030195
Copy link

the hype is too strong :/

@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