reddit.com - Sort by Top Quicker (past hour/24 hours/week/month/year/all time).

All the 'sort by top' options are made available for single clicking. And it actually looks good too.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name				reddit.com - Sort by Top Quicker (past hour/24 hours/week/month/year/all time).
// @namespace			a-pav
// @description			All the 'sort by top' options are made available for single clicking. And it actually looks good too.
// @match				*://*.reddit.com/*
// @exclude-match		*://*.reddit.com/search?*
// @exclude-match		*://*.reddit.com/r/*/search?*
// @match              	*://reddit.com/*
// @exclude-match		*://reddit.com/search?*
// @exclude-match		*://reddit.com/r/*/search?*
// @version				1.0
// @run-at				document-end
// @author				a-pav
// @icon				https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-76x76.png
// ==/UserScript==

// operates on old design.
var top_a = document.querySelector('ul.tabmenu>li>a[href*="/top/"');
if (top_a === null) {
	return
}

var view = ""

if (window.location.pathname.includes("/top/")) { // we are on a */top/* url
	const re = /hour\b|24|week|month|year|all/;
	var  view = document.querySelector("div.menuarea>div>div.dropdown.lightdrop>span").innerText;
	if (re.test(view)) {
		view = view.match(re)[0]
	}
}

function isView(txt) {
	return txt === view;
}

var html = `
	<li class='${isView("hour") ? 'selected' : ''}'>
		<a class='choice' href='${top_a.href}?sort=top&t=hour'>-1h</a>
	</li>
	<li class='${isView("24") ? 'selected' : ''}'>
		<a class="choice" href='${top_a.href}?sort=top&t=day'>-24h</a>
	</li>
	<li class='${isView("week") ? 'selected' : ''}'>
		<a class="choice" href='${top_a.href}?sort=top&t=week'>-W</a>
	</li>
	<li class='${isView("month") ? 'selected' : ''}'>
		<a class="choice" href='${top_a.href}?sort=top&t=month'>-M</a>
	</li>
	<li class='${isView("year") ? 'selected' : ''}'>
		<a class="choice" href='${top_a.href}?sort=top&t=year'>-Y</a>
	</li>
	<li class='${isView("all") ? 'selected' : ''}'>
		<a class="choice" href='${top_a.href}?sort=top&t=all'>-A</a>
	</li>
`;

top_a.parentElement.insertAdjacentHTML("afterend", html);