Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Hide AI and GPT posts
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Hides ChatGPT related posts from HackerNews. If you can't see AI it can't take your job.
- // @author https://news.ycombinator.com/user?id=quiet_light
- // @match https://news.ycombinator.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com
- // ==/UserScript==
- (function() {
- 'use strict';
- window.onload = function () {
- // Regular expression to match the keywords "AI" or "GPT"
- const keywordRegex = /\b(AI|GPT)\b/i;
- // Find all the submissions on the page
- const submissions = document.querySelectorAll(".athing");
- const filteredLinks = [];
- const isHomePage = window.location.href.match("https://news.ycombinator.com/$") || window.location.href.match("https://news.ycombinator.com/news/*");
- if (!isHomePage) {
- return;
- }
- // Loop through the submissions
- for (let i = 0; i < submissions.length; i++) {
- const submission = submissions[i];
- // Find the submission title and metadata(author, points, etc) elements
- const title = submission.querySelector(".title a");
- const submissionMetaData = submission.nextElementSibling;
- // Check if the submission title contains the keywords
- const shouldRemove = (title && keywordRegex.test(title.textContent))
- if (shouldRemove) {
- const link = {
- title: title ? title.textContent.trim() : "",
- url: 'https://news.ycombinator.com/item?id=' + submission.getAttribute('id')
- };
- filteredLinks.push(link);
- submission.parentNode.removeChild(submission);
- submissionMetaData.parentNode.removeChild(submissionMetaData);
- }
- }
- console.log(filteredLinks);
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment