vrchat one-time code

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

目前為 2023-09-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         vrchat one-time code
// @version      1.3
// @description  使用按鈕複製Gmail內的vrchat one-time code
// @author       BaconEgg
// @match        https://mail.google.com/mail/u/0/?tab=*
// @grant        none
// @namespace https://greasyfork.org/users/735944
// ==/UserScript==
(function() {
    'use strict';

    const delay = 2000; // 2秒延遲載入按鈕, 沒按鈕的話就加大數字

    function generateSelector(elementId) {
        return `#\\${elementId} > div:nth-child(2) > p:nth-child(4) > b`;
    }

    function copyTextToClipboard(text) {
        const textArea = document.createElement("textarea");
        textArea.value = text;
        document.body.appendChild(textArea);
        textArea.select();
        document.execCommand("copy");
        document.body.removeChild(textArea);
    }

    function handleButtonClick() {
        const elements = document.querySelectorAll('.a3s.aiL');
        elements.forEach(function(element) {
            const elementId = element.getAttribute('id');
            if (elementId) {
                const selector = generateSelector(elementId);
                const element2 = document.querySelector(selector);
                if (element2) {
                    const textToCopy = element2.textContent.trim();
                    copyTextToClipboard(textToCopy);
                }
            }
        });
    }

    function addButton() {
        const customButton = document.createElement('button');
        customButton.textContent = 'VRChat code';
        customButton.addEventListener('click', handleButtonClick);

        const buttonParent = document.querySelectorAll('.gb_de.gb_be.bGJ')[0];

        if (buttonParent) {
            buttonParent.appendChild(customButton);
        }
    }

    // 在頁面載入完成後執行
    window.addEventListener('load', () => {
        setTimeout(addButton, delay);
    });
})();