Greasy Fork

Greasy Fork is available in English.

Simplify Xiaohongshu Link

Simplify Xiaohongshu URL and copy to clipboard with toast notification

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Simplify Xiaohongshu Link
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Simplify Xiaohongshu URL and copy to clipboard with toast notification
// @author       anthonymo
// @license MIT
// @match        *://www.xiaohongshu.com/*
// @grant        GM_setClipboard
// ==/UserScript==

(function () {
    'use strict';

    const btn = document.createElement('button');
    btn.innerText = '🔗 复制简化链接';
    Object.assign(btn.style, {
        position: 'fixed',
        top: '12px',
        right: '12px',
        zIndex: '9999',
        backgroundColor: '#f8f8f8',
        color: '#333',
        border: '1px solid #ccc',
        borderRadius: '8px',
        padding: '6px 10px',
        fontSize: '13px',
        fontFamily: 'sans-serif',
        cursor: 'pointer',
        boxShadow: '0 2px 4px rgba(0,0,0,0.08)',
        transition: 'all 0.2s ease',
    });

    btn.addEventListener('mouseover', () => {
        btn.style.boxShadow = '0 4px 8px rgba(0,0,0,0.12)';
    });
    btn.addEventListener('mouseout', () => {
        btn.style.boxShadow = '0 2px 4px rgba(0,0,0,0.08)';
    });

    document.body.appendChild(btn);

    function showToast(msg) {
        const toast = document.createElement('div');
        toast.innerText = msg;
        Object.assign(toast.style, {
            position: 'fixed',
            top: '60px',
            right: '16px',
            backgroundColor: 'rgba(50,50,50,0.85)',
            color: '#fff',
            padding: '6px 14px',
            borderRadius: '6px',
            zIndex: '10000',
            fontSize: '13px',
            opacity: '1',
            transition: 'opacity 0.4s ease-out',
        });
        document.body.appendChild(toast);

        setTimeout(() => {
            toast.style.opacity = '0';
            setTimeout(() => toast.remove(), 400);
        }, 1800);
    }

    function simplifyLink(url) {
        const base = url.split('?')[0];
        const query = new URLSearchParams(url.split('?')[1] || '');
        const token = query.get('xsec_token');
        return token ? `${base}?xsec_token=${encodeURIComponent(token)}` : base;
    }

    btn.addEventListener('click', () => {
        const simplified = simplifyLink(window.location.href);
        GM_setClipboard(simplified, 'text');
        showToast('✅ 已复制简化链接');
    });
})();