Reddit Hide All Posts & Reload Hotkey

Hide all posts & reload page on Ctrl+Shift+R; cancel with Escape

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

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 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.

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

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         Reddit Hide All Posts & Reload Hotkey
// @namespace    redditposthideandreload_kk
// @version      1.5
// @description  Hide all posts & reload page on Ctrl+Shift+R; cancel with Escape
// @match        https://*.reddit.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

let oldhidebtns;
let newhidebtns;

function getbtns() {
	oldhidebtns = document.getElementsByTagName("a");
	newhidebtns = document.getElementsByClassName("icon-hide");
}

let wait = ms => new Promise(resolve => setTimeout(resolve, ms));
let waitTime = 500;
let canReload = true;

async function doHide() {
	getbtns();

	try {
		for (let i = 0; i < oldhidebtns.length; i++) {
			if (!canReload) return;

			if (oldhidebtns[i].innerText.toLowerCase() === "hide") {
				oldhidebtns[i].click();
				await wait(waitTime);
			}
		}

		let didNewBtnRun = false;

		for (let i = 1; i < newhidebtns.length; i++) {
			if (!canReload) return;
			i--;

			newhidebtns[i].click();
			didNewBtnRun = true;
			await wait(waitTime);
		}

		if (didNewBtnRun) return doHide();

		await wait(waitTime + 1000);

		if (!canReload) return;

		location.reload();
	}
	catch (e) {
		console.warn(e);
		doHide();
	}
}

document.addEventListener("keydown", (e) => {
	if (e.ctrlKey && e.shiftKey && e.keyCode == 82) {
		e.preventDefault();
		canReload = true;
		doHide();
	}
	if (e.key.toLowerCase() === "escape" || e.code.toLowerCase() === "escape") {
		e.preventDefault();
		canReload = false;
	}
}, false);