LeetCode url清理

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

Tính đến 12-11-2025. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
    }
})();