跳到正文

科技·工程

自动改“默认排序”为“最新评论”

FlowerRed约 2 分钟
原文

这是 2025年9月5日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1
JavaScript
// ==UserScript==
// @name         自动改“默认排序”为“最新评论”
// @namespace    https://www.luogu.com.cn/user/1510406
// @version      1.0
// @description  自动改“默认排序”为“最新评论”。
// @author       FlowerRed
// @match        https://www.luogu.com.cn/article/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function run() {
        let sel = '.comment-filter-line .combo-wrapper';
        let btn = document.querySelector(sel);
        if (btn && btn.textContent.includes('默认排序')) {
            btn.click();
            setTimeout(selopt, 100);
        }
    }

    function selopt() {
        let opts = document.querySelectorAll('.dropdown li');
        for (let opt of opts) {
            if (opt.textContent.trim() === '最新评论') {
                opt.click();
                break;
            }
        }
    }

    setTimeout(run, 100);
})();