小红书链接简化

Modify the URL to keep only specific parameters

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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.

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

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         小红书链接简化
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Modify the URL to keep only specific parameters
// @author       Larynx
// @match        https://www.xiaohongshu.com/*
// @license MIT
// @grant        none
// @run-at		document-start
// ==/UserScript==

(function() {
    'use strict';

    // 获取当前的 URL
    const url = new URL(window.location.href);

    // 提取需要的参数
    const xsec_source = url.searchParams.get('xsec_source');
    const xsec_token = url.searchParams.get('xsec_token');

    // 构造新的 URL
    const newUrl = `${url.origin}${url.pathname}?`;

    const params = new URLSearchParams();
    if (xsec_source) params.append('xsec_source', xsec_source);
    if (xsec_token) params.append('xsec_token', xsec_token);

    // 如果参数存在,则更新 URL
    if (params.toString()) {
        window.history.replaceState(null, '', newUrl + params.toString());
        //window.location.replace(newUrl + params.toString());
    }
})();