vrchat one-time code

使用按鈕複製Gmail內的vrchat one-time code

当前为 2025-03-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name vrchat one-time code
  3. // @version 2.0
  4. // @description 使用按鈕複製Gmail內的vrchat one-time code
  5. // @author BaconEgg
  6. // @match https://mail.google.com/mail/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/735944
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12.  
  13. const otpRegex = /Your One-Time Code is (\d{6})/;
  14.  
  15. function getRandomColor() {
  16. return `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
  17. }
  18.  
  19. function extractOTP() {
  20. const element = [...document.querySelectorAll("span, div")].find(el => otpRegex.test(el.textContent));
  21. if (element) {
  22. const otp = element.textContent.match(otpRegex)[1];
  23. GM_setClipboard(otp);
  24. document.getElementById('customOTPButton').style.background = getRandomColor();
  25. }
  26. }
  27.  
  28. function addButton() {
  29. if (document.getElementById('customOTPButton')) return; // Prevent duplicate button
  30.  
  31. const customButton = document.createElement('button');
  32. customButton.id = 'customOTPButton';
  33. customButton.textContent = 'VRChat code';
  34. customButton.addEventListener('click', extractOTP);
  35.  
  36. Object.assign(customButton.style, {
  37. padding: "10px 15px",
  38. background: "#4285F4",
  39. color: "#fff",
  40. border: "none",
  41. borderRadius: "5px",
  42. cursor: "pointer"
  43. });
  44.  
  45. const buttonParent = document.querySelector('.bGJ');
  46. if (buttonParent) buttonParent.appendChild(customButton);
  47. }
  48.  
  49. window.addEventListener("load", () => setTimeout(addButton, 1000));
  50. })();