// ==UserScript== // @name Old Reddit Top Filters (1h,3h,6h,12h,24h,W,M,Y,all) // @description Add quick "top" filter shortcut buttons to the tab menu. // @version 2.3 // @author C89sd // @namespace https://greasyfork.org/users/1376767 // @match https://old.reddit.com/* // @noframes // @downloadURL https://update.greasyfork.icu/scripts/536708/Old%20Reddit%20Top%20Filters%20%281h%2C3h%2C6h%2C12h%2C24h%2CW%2CM%2CY%2Call%29.user.js // @updateURL https://update.greasyfork.icu/scripts/536708/Old%20Reddit%20Top%20Filters%20%281h%2C3h%2C6h%2C12h%2C24h%2CW%2CM%2CY%2Call%29.meta.js // ==/UserScript== const MS_TABLE = { h: 3600e3, d: 86400e3, w: 604800e3, m: 2592e6, y: 31536e6 }; const BUTTONS = [ { lbl: '1h', t: 'hour', filter: '' }, { lbl: '3h', t: 'day', filter: '3h' }, // may scrape too many pages on large subs //{ lbl: '4h', t: 'day', filter: '4h' }, { lbl: '6h', t: 'day', filter: '6h' }, { lbl: '12h', t: 'day', filter: '12h'}, { lbl: '24h', t: 'day', filter: '' }, { lbl: 'W', t: 'week', filter: '' }, //{ lbl: '2W', t: 'month', filter: '2w' }, { lbl: 'M', t: 'month', filter: '' }, //{ lbl: '3M', t: 'year', filter: '3m' }, // may scrape too many pages on large subs //{ lbl: '6M', t: 'year', filter: '6m' }, { lbl: 'Y', t: 'year', filter: '' }, { lbl: 'all', t: 'all', filter: '' }, ]; const FILTER_REGEX = /#filter=(\d+)([hdwmy])/i; const MIN_POSTS = 25; const FETCH_DELAY_MS = 750; window.filterClick = function filterClick(e){ const hrefClean = e.currentTarget.href.replace(/#.*/,''); const hereClean = location.href.replace(/#.*/,''); if (hrefClean === hereClean) setTimeout(() => location.reload(), 100); }; const tabMenu = document.querySelector('.tabmenu'); if (tabMenu) { let fetchController = new AbortController(); window.addEventListener('pagehide', () => fetchController.abort()); const { origin, pathname } = window.location; const isFrontOrAllPage = pathname === '/' || pathname.startsWith('/r/all'); const pathPrefix = (pathname.match(/^(\/r\/[^/]+|\/user\/[^/]+\/m\/[^/]+)/) || [''])[0]; const baseUrl = `${origin}${pathPrefix}/top/?sort=top`; const styleTag = document.createElement('style'); styleTag.textContent = '.ggray { filter: saturate(0.1) !important; }'; document.head.appendChild(styleTag); const tMatch = location.search.match(/[?&]t=([^]+)/i); const curT = tMatch ? tMatch[1] : ''; const curFilterRx = location.hash.match(FILTER_REGEX); const curFilter = curFilterRx ? curFilterRx[1] + curFilterRx[2] : ''; const buttonsHTML = BUTTONS .filter(btn => !(isFrontOrAllPage && btn.t === 'year')) .map(btn => { const url = `${baseUrl}&t=${btn.t}`; const href = btn.filter ? `${url}#filter=${btn.filter}` : url; const click = btn.filter ? 'onclick="filterClick(event)"' : ''; const isSel = curT === btn.t && curFilter === btn.filter; const liCls = isSel ? 'selected' : (btn.filter ? 'ggray' : ''); return `