Scrolller.com Redirector

Redirect Scrolller subreddit pages to sorted and filtered view

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Scrolller.com Redirector
// @namespace     http://tampermonkey.net/
// @license       MIT
// @version       0.1
// @description   Redirect Scrolller subreddit pages to sorted and filtered view
// @icon          https://scrolller.com/assets/favicon-16x16.png
// @author        nkatshiba
// @match         https://scrolller.com/r/*
// @grant         none
// @run-at        document-start
// ==/UserScript==

(function() {
    'use strict';

    // Get the current URL
    var currentUrl = new URL(window.location.href);

    // Check if the URL already contains the desired parameters
    var params = currentUrl.searchParams;

    // Only add the parameters if they are not already set correctly
    var needsRedirect = false;
    if (params.get('sort') !== 'rising') {
        params.set('sort', 'rising');
        needsRedirect = true;
    }
    if (params.get('filter') !== 'videos') {
        params.set('filter', 'videos');
        needsRedirect = true;
    }

    // Construct the new URL if needed
    if (needsRedirect) {
        var newUrl = currentUrl.origin + currentUrl.pathname + '?' + params.toString();
        window.location.replace(newUrl);
    }
})();