LeetCode url清理

Removes query strings from LeetCode problem description pages. (移除 LeetCode 题目描述页面的查询参数)

Od 12.11.2025.. Pogledajte najnovija verzija.

// ==UserScript==
// @name        LeetCode url清理
// @namespace   http://tampermonkey.net/
// @version     0.1
// @description Removes query strings from LeetCode problem description pages. (移除 LeetCode 题目描述页面的查询参数)
// @author      leone
// @match       https://leetcode.cn/problems/*/description/?*
// @grant       none
// @run-at      document-start
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // @match 规则确保了这个脚本只会在
    // 访问 /description/ 并且后面带了查询参数 (?) 的页面上运行。

    // 获取当前的网址
    const currentUrl = window.location.href;

    // 通过 '?' 分割网址,并获取第一部分(即干净的网址)
    const cleanUrl = currentUrl.split('?')[0];

    // 跳转到干净的网址
    // 使用 replace 来替换当前的历史记录,这样点击“后退”按钮时
    // 就不会退回到带参数的网址了。
    if (currentUrl !== cleanUrl) {
        window.location.replace(cleanUrl);
    }
})();