LeetCode url清理

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

目前為 2025-11-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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