Skip to content

Instantly share code, notes, and snippets.

@namuan
Created March 23, 2023 06:03
Show Gist options
  • Select an option

  • Save namuan/c979b99080e571fe82f527d8b6a7adfe to your computer and use it in GitHub Desktop.

Select an option

Save namuan/c979b99080e571fe82f527d8b6a7adfe to your computer and use it in GitHub Desktop.

Revisions

  1. namuan created this gist Mar 23, 2023.
    52 changes: 52 additions & 0 deletions hn-hide-mainstream-media.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    // ==UserScript==
    // @name Hide Links From Mainstream Media
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @description Hides all links from mainstream media websites on news.ycombinator
    // @match https://news.ycombinator.com/*
    // @grant none
    // ==/UserScript==

    (function() {
    'use strict';

    // Specify the list of mainstream media website substrings to check for
    var mainstreamMediaWebsites = [
    "cnn.com",
    "bbc.com",
    "nytimes.com",
    "washingtonpost.com",
    "theguardian.com",
    "abcnews.go.com",
    "nbcnews.com",
    "cbsnews.com",
    "foxnews.com",
    "msnbc.com",
    "npr.org",
    "reuters.com",
    "apnews.com",
    "aljazeera.com",
    "bloomberg.com",
    "forbes.com",
    "ft.com",
    "wsj.com",
    "arstechnica.com"
    ];

    // Find all HTML elements containing links
    var linkElements = document.querySelectorAll("a[href^='from?site=']");

    // Loop through all link elements and remove the closest <tr> element with class 'athing' to the link if the link is from a mainstream media website
    for (var i = 0; i < linkElements.length; i++) {
    var link = linkElements[i];
    if (link.href) {
    if (mainstreamMediaWebsites.some(function(site) { return link.href.includes(site); })) {
    var tr = link.closest("tr.athing");
    if (tr) {
    // Hide the <tr> element
    tr.style.display = "none";
    }
    }
    }
    }
    })();