Greasy Fork

Greasy Fork is available in English.

小说ID自动复制

自动提取小说ID并复制,方便粘贴使用

目前为 2025-05-15 提交的版本,查看 最新版本

// ==UserScript==
// @name         小说ID自动复制
// @namespace    http://tampermonkey.net/
// @version      1.01
// @description  自动提取小说ID并复制,方便粘贴使用
// @author       YourName
// @match        *://*/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==


(function() {
    'use strict';

    // 匹配网址中的6位以上数字作为小说ID(根据你的网站自行调整)
    const match = location.href.match(/\/(?:book|novel|reader)?\/?(\d{6,})/i);
    if (!match) return;

    const novelId = match[1];

    // 复制到剪贴板
    if (typeof GM_setClipboard !== "undefined") {
        GM_setClipboard(novelId);
    } else {
        const input = document.createElement("textarea");
        input.value = novelId;
        document.body.appendChild(input);
        input.select();
        document.execCommand("copy");
        document.body.removeChild(input);
    }

    // 提示框
    const msg = document.createElement("div");
    msg.innerText = `小说ID ${novelId} 已复制到剪贴板`;
    Object.assign(msg.style, {
        position: "fixed",
        top: "20px",
        right: "20px",
        background: "#28a745",
        color: "white",
        padding: "10px 15px",
        borderRadius: "10px",
        zIndex: 9999,
        fontSize: "14px",
        boxShadow: "0 2px 8px rgba(0,0,0,0.2)"
    });
    document.body.appendChild(msg);
    setTimeout(() => msg.remove(), 3000);
})();