vrchat one-time code

複製vrchat one-time code beta版

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

  1. // ==UserScript==
  2. // @name vrchat one-time code
  3. // @version 1.0
  4. // @description 複製vrchat one-time code beta版
  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. // 查找具有 class "a3s aiL " 的元素
  24. const elements = document.querySelectorAll('.a3s.aiL');
  25.  
  26. if (elements.length > 0) {
  27. // 遍歷匹配的元素並處理它們
  28. elements.forEach(function(element) {
  29. const elementId = element.getAttribute('id');
  30. if (elementId) {
  31. // 創建自定義按鈕
  32. const customButton = document.createElement('button');
  33. customButton.textContent = 'vrchat code';
  34.  
  35. // 添加按鈕點擊事件處理程序
  36. customButton.addEventListener('click', function() {
  37. const selector = generateSelector(elementId);
  38. const element2 = document.querySelector(selector);
  39. if (element2) {
  40. // 複製元素的文本內容到剪貼板
  41. const textToCopy = element2.textContent.trim();
  42. const textArea = document.createElement("textarea");
  43. textArea.value = textToCopy;
  44. document.body.appendChild(textArea);
  45. textArea.select();
  46. document.execCommand("copy");
  47. document.body.removeChild(textArea);
  48. }
  49. });
  50.  
  51. // 找到按鈕的父元素
  52. 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");
  53.  
  54. if (buttonParent) {
  55. // 將自定義按鈕插入到按鈕的父元素中
  56. buttonParent.appendChild(customButton);
  57. }
  58. }
  59. });
  60. }
  61. }, delay);
  62. })();