HNCleaner

Remove annoying HN posts

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         HNCleaner
// @namespace    LWPDWyfub
// @version      0.2
// @description  Remove annoying HN posts
// @author       LWPDWyfub
// @match https://news.ycombinator.com/*
// @exclude https://news.ycombinator.com/item*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ycombinator.com
// @license MIT
// ==/UserScript==

(function () {
	'use strict';
	const annoyingTerms = [
		'ChatGPT',
		'Musk',
		'Elon',
		'spacex',
		'tesla'
	];
	const annoyingSites = ['twitter.com'];
	const annoyingTermsRegex = new RegExp('(' + annoyingTerms.join('|') + ')', 'i')
	const annoyingSitesRegex = new RegExp('(' + annoyingSites.join('|') + ')', 'i')
	const termTargets = Array.from(document.querySelectorAll('.athing')).filter(({ innerText }) => annoyingTermsRegex.test(innerText) || annoyingSitesRegex.test(innerText))
	const logoutButton = document.querySelector("#logout")
	const hidePost = function (postIds, next) {
		var postId = postIds[next].id
		console.log("Hiding post[" + next + "] with ID " + postId)
		var req = XMLHttpRequest({
			method: 'GET',
			url: "https://news.ycombinator.com/hide?id=" + postId,
			withCredentials: true,
			onerror: function (error) {
				console.log("Error hiding " + postId)
			},
			onload: function (response) {
				var resp = response.responseText;
				console.log("Hiding post " + postId + " returned code " + response.status)
				if (resp.includes("Logged") || resp.status != 200) {
					console.log(resp)
				}
				else {
					console.log("Hid post " + postId)
				}

			}
		});
		next = next + 1
		if (next < postIds.length) {
			window.setTimeout(hidePost, 5000, termTargets, next)
		}
		else {
			console.log("Finished hiding final post")
		}
	}

	console.log("Found " + termTargets.length + " annoying targets")
	for (let target of termTargets) {
		console.log("Hiding post " + target.id)
		target.style.display = "none"
	}
	// Clean up spacers and comments
	Array.from(document.querySelectorAll("tr[style*='none'] + tr")).forEach(function (e) { e.style.display = "none" })
	Array.from(document.querySelectorAll("tr[style*='none'] + .spacer")).forEach(function (e) { e.style.display = "none" })

	// Renumber unhidden posts
	var allRanks = Array.from(document.querySelectorAll("span.rank"))
	var shownSpans = Array.from(document.querySelectorAll("span.rank")).filter(
		e => window.getComputedStyle(e.parentElement.parentElement).display != "none")
	const firstNum = parseInt(allRanks[0].innerText.replace("\.", ""))
	for (let i = 0; i < shownSpans.length; i++) {
		shownSpans[i].innerText = (firstNum + i) + "."
	}


})();