Greasy Fork镜像 还支持 简体中文。

Beanfun QR Code Click-to-Copy

在 beanfun! QR Code 登入頁面,點擊 QR Code 圖片時,自動複製其連結到剪貼簿。

目前為 2025-05-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Beanfun QR Code Click-to-Copy
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  在 beanfun! QR Code 登入頁面,點擊 QR Code 圖片時,自動複製其連結到剪貼簿。
// @author       eunalice (Generated by Gemini 2.5 Pro)
// @match        *://*.beanfun.com/loginform.aspx*
// @match        *://tw.newlogin.beanfun.com/loginform.aspx*
// @grant        GM_setClipboard
// @grant        GM_addStyle
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const IFRAME_ID = 'ifmForm8';
    const QR_CODE_IMAGE_SELECTOR = '#theQrCodeImg';
    const PREFIX_TO_REMOVE = 'https://tw.newlogin.beanfun.com/qrhandler.ashx?u=';
    const NOTIFICATION_ID = 'gm-qr-copy-notify';

    GM_addStyle(`
        #${NOTIFICATION_ID} {
            position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
            background-color: rgba(0, 0, 0, 0.8); color: white; padding: 10px 20px;
            border-radius: 5px; z-index: 10000; font-size: 14px;
            opacity: 0; transition: opacity 0.5s ease-in-out; pointer-events: none;
        }
        #${NOTIFICATION_ID}.visible { opacity: 1; }
    `);

    function showNotification(message, duration = 3000) {
        let notify = document.getElementById(NOTIFICATION_ID);
        if (!notify) {
            notify = document.createElement('div');
            notify.id = NOTIFICATION_ID;
            document.body.appendChild(notify);
        }
        notify.textContent = message;
        notify.offsetHeight;
        notify.classList.add('visible');
        if (notify.timer) clearTimeout(notify.timer);
        notify.timer = setTimeout(() => {
            notify.classList.remove('visible');
        }, duration);
    }

    const checkInterval = setInterval(() => {
        const targetIframe = document.getElementById(IFRAME_ID);
        if (targetIframe) {
            clearInterval(checkInterval);

            targetIframe.addEventListener('load', () => {
                 try {
                    setTimeout(() => {
                        const iframeDoc = targetIframe.contentDocument || targetIframe.contentWindow?.document;
                        if (!iframeDoc) {
                            return;
                        }

                        const qrImageElement = iframeDoc.querySelector(QR_CODE_IMAGE_SELECTOR);

                        if (qrImageElement) {
                            qrImageElement.style.cursor = 'pointer';
                            qrImageElement.title = '點擊以複製鏈結';

                            qrImageElement.replaceWith(qrImageElement.cloneNode(true));
                            const newQrImageElement = iframeDoc.querySelector(QR_CODE_IMAGE_SELECTOR);
                            if (!newQrImageElement) return;

                            newQrImageElement.addEventListener('click', (event) => {
                                event.preventDefault();

                                let qrUrl = newQrImageElement.src || newQrImageElement.dataset.url;

                                if (qrUrl && String(qrUrl).trim()) {
                                    let originalUrl = String(qrUrl).trim();
                                    let finalValueToCopy = originalUrl;

                                    if (originalUrl.startsWith(PREFIX_TO_REMOVE)) {
                                        finalValueToCopy = originalUrl.substring(PREFIX_TO_REMOVE.length);
                                    }

                                    GM_setClipboard(finalValueToCopy);
                                    showNotification('已複製鏈結!');

                                } else {
                                    showNotification('錯誤:無法從圖片獲取有效資料');
                                }
                            });

                        } else {
                            // Element not found, do nothing silently in cleaned version
                        }
                    }, 100);

                 } catch (e) {
                     if (e.name === 'SecurityError') {
                         showNotification('錯誤:無法設定點擊事件 (安全性限制)');
                     } else {
                         showNotification('設定點擊事件時發生錯誤');
                     }
                 }
             });
        }
    }, 500);

    setTimeout(() => {
        clearInterval(checkInterval);
    }, 15000);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址