Beanfun QR Code Click-to-Copy

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

当前为 2025-05-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Beanfun QR Code Click-to-Copy
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description 在 beanfun! QR Code 登入頁面,點擊 QR Code 圖片時,自動複製其連結到剪貼簿。
  6. // @author eunalice (Generated by Gemini 2.5 Pro)
  7. // @match *://*.beanfun.com/loginform.aspx*
  8. // @match *://tw.newlogin.beanfun.com/loginform.aspx*
  9. // @grant GM_setClipboard
  10. // @grant GM_addStyle
  11. // @run-at document-end
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const IFRAME_ID = 'ifmForm8';
  19. const QR_CODE_IMAGE_SELECTOR = '#theQrCodeImg';
  20. const PREFIX_TO_REMOVE = 'https://tw.newlogin.beanfun.com/qrhandler.ashx?u=';
  21. const NOTIFICATION_ID = 'gm-qr-copy-notify';
  22.  
  23. GM_addStyle(`
  24. #${NOTIFICATION_ID} {
  25. position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  26. background-color: rgba(0, 0, 0, 0.8); color: white; padding: 10px 20px;
  27. border-radius: 5px; z-index: 10000; font-size: 14px;
  28. opacity: 0; transition: opacity 0.5s ease-in-out; pointer-events: none;
  29. }
  30. #${NOTIFICATION_ID}.visible { opacity: 1; }
  31. `);
  32.  
  33. function showNotification(message, duration = 3000) {
  34. let notify = document.getElementById(NOTIFICATION_ID);
  35. if (!notify) {
  36. notify = document.createElement('div');
  37. notify.id = NOTIFICATION_ID;
  38. document.body.appendChild(notify);
  39. }
  40. notify.textContent = message;
  41. notify.offsetHeight;
  42. notify.classList.add('visible');
  43. if (notify.timer) clearTimeout(notify.timer);
  44. notify.timer = setTimeout(() => {
  45. notify.classList.remove('visible');
  46. }, duration);
  47. }
  48.  
  49. const checkInterval = setInterval(() => {
  50. const targetIframe = document.getElementById(IFRAME_ID);
  51. if (targetIframe) {
  52. clearInterval(checkInterval);
  53.  
  54. targetIframe.addEventListener('load', () => {
  55. try {
  56. setTimeout(() => {
  57. const iframeDoc = targetIframe.contentDocument || targetIframe.contentWindow?.document;
  58. if (!iframeDoc) {
  59. return;
  60. }
  61.  
  62. const qrImageElement = iframeDoc.querySelector(QR_CODE_IMAGE_SELECTOR);
  63.  
  64. if (qrImageElement) {
  65. qrImageElement.style.cursor = 'pointer';
  66. qrImageElement.title = '點擊以複製鏈結';
  67.  
  68. qrImageElement.replaceWith(qrImageElement.cloneNode(true));
  69. const newQrImageElement = iframeDoc.querySelector(QR_CODE_IMAGE_SELECTOR);
  70. if (!newQrImageElement) return;
  71.  
  72. newQrImageElement.addEventListener('click', (event) => {
  73. event.preventDefault();
  74.  
  75. let qrUrl = newQrImageElement.src || newQrImageElement.dataset.url;
  76.  
  77. if (qrUrl && String(qrUrl).trim()) {
  78. let originalUrl = String(qrUrl).trim();
  79. let finalValueToCopy = originalUrl;
  80.  
  81. if (originalUrl.startsWith(PREFIX_TO_REMOVE)) {
  82. finalValueToCopy = originalUrl.substring(PREFIX_TO_REMOVE.length);
  83. }
  84.  
  85. GM_setClipboard(finalValueToCopy);
  86. showNotification('已複製鏈結!');
  87.  
  88. } else {
  89. showNotification('錯誤:無法從圖片獲取有效資料');
  90. }
  91. });
  92.  
  93. } else {
  94. // Element not found, do nothing silently in cleaned version
  95. }
  96. }, 100);
  97.  
  98. } catch (e) {
  99. if (e.name === 'SecurityError') {
  100. showNotification('錯誤:無法設定點擊事件 (安全性限制)');
  101. } else {
  102. showNotification('設定點擊事件時發生錯誤');
  103. }
  104. }
  105. });
  106. }
  107. }, 500);
  108.  
  109. setTimeout(() => {
  110. clearInterval(checkInterval);
  111. }, 15000);
  112.  
  113. })();

QingJ © 2025

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