vrchat one-time code

複製vrchat one-time code

当前为 2023-09-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name vrchat one-time code
  3. // @version 1.1
  4. // @description 複製vrchat one-time code
  5. // @author BaconEgg
  6. // @match https://mail.google.com/mail/u/0/?tab=*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/735944
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // 生成選擇器
  15. function generateSelector(elementId) {
  16. return `#\\${elementId} > div:nth-child(2) > p:nth-child(4) > b`;
  17. }
  18.  
  19. const delay = 2000; // 延遲時間,例如2秒的延遲
  20.  
  21. // 在頁面加載完成後執行
  22. setTimeout(() => {
  23. // 創建自定義按鈕
  24. const customButton = document.createElement('button');
  25. customButton.textContent = 'vrchat code';
  26.  
  27. // 找到按鈕的父元素
  28. const buttonParent = document.querySelector("#gb > div.gb_ld.gb_fd.gb_rd.gb_Jc > div.gb_kd.gb_ud.gb_ze.gb_Me.gb_Re > div.gb_ce.gb_ae.bGJ");
  29.  
  30. if (buttonParent) {
  31. // 將自定義按鈕插入到按鈕的父元素中
  32. buttonParent.appendChild(customButton);
  33. }
  34.  
  35. // 添加按鈕點擊事件處理程序
  36. customButton.addEventListener('click', function() {
  37. // 查找具有 class "a3s aiL" 的元素
  38. const elements = document.querySelectorAll('.a3s.aiL');
  39.  
  40. if (elements.length > 0) {
  41. // 遍歷匹配的元素並處理它們
  42. elements.forEach(function(element) {
  43. const elementId = element.getAttribute('id');
  44. if (elementId) {
  45. const selector = generateSelector(elementId);
  46. const element2 = document.querySelector(selector);
  47. if (element2) {
  48. // 複製元素的文本內容到剪貼板
  49. const textToCopy = element2.textContent.trim();
  50. const textArea = document.createElement("textarea");
  51. textArea.value = textToCopy;
  52. document.body.appendChild(textArea);
  53. textArea.select();
  54. document.execCommand("copy");
  55. document.body.removeChild(textArea);
  56. }
  57. }
  58. });
  59. }
  60. });
  61.  
  62. }, delay);
  63. })();