FC2PPV 番號提取器

提取頁面中的6-8位數字並複製到剪貼簿

// ==UserScript==
// @name         FC2PPV 番號提取器
// @namespace    http://tampermonkey.net/
// @version      1.1.1
// @description  提取頁面中的6-8位數字並複製到剪貼簿
// @author       YourName
// @match        https://fc2ppvdb.com/*
// @icon         https://www.google.com/s2/favicons?domain=fc2ppvdb.com
// @grant        GM_setClipboard
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 自定義提示框樣式
    GM_addStyle(`
        .custom-alert {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px;
            background: #9999ff;
            border: 1px solid #f5c6cb;
            border-radius: 4px;
            z-index: 9999;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
    `);

    // 創建可自動關閉的提示框
    function showAutoCloseAlert(message, duration = 3000) {
        const alertBox = document.createElement('div');
        alertBox.className = 'custom-alert';
        alertBox.textContent = message;
        document.body.appendChild(alertBox);

        setTimeout(() => {
            alertBox.remove();
        }, duration);
    }

    // 提取數字並複製到剪貼板
    function extractAndCopy() {
        const pageText = document.body.textContent;
        const numberRegex = /\b\d{6,8}\b/g;
        const matches = [...new Set(pageText.match(numberRegex) || [])];

        if (matches.length === 0) {
            showAutoCloseAlert("未找到6-8位數字");
            return;
        }

        const result = matches.join('\r\n');
        GM_setClipboard(result);
        showAutoCloseAlert(`已複製 ${matches.length} 個數字到剪貼簿`);
    }

    // 修改熱鍵為 F8 (單獨按鍵)
    document.addEventListener('keydown', (e) => {
        // 如需使用單獨F8做觸發,則將下面這些區域註解移除即可
		/* 
        if (e.key === 'F8') { // 直接按F8觸發
            extractAndCopy();
            e.preventDefault(); // 阻止瀏覽器默認行為
        }
        */

        // 使用 Ctrl+Shift+F8作為啟動鍵,以利本機部分用ahk調用,調複雜一點,避免熱鍵衝突
        if (e.ctrlKey && e.shiftKey && e.key === 'F8') {
            extractAndCopy();
            e.preventDefault();
        }
    });

    // 測試階段自動執行(按需啟用)
    // setTimeout(extractAndCopy, 2000);
})();