vrchat one-time code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    const otpRegex = /Your One-Time Code is (\d{6})/;

    function getRandomColor() {
        return `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
    }

    function extractOTP() {
        const element = [...document.querySelectorAll("span, div")].find(el => otpRegex.test(el.textContent));
        if (element) {
            const otp = element.textContent.match(otpRegex)[1];
            GM_setClipboard(otp);
            document.getElementById('customOTPButton').style.background = getRandomColor();
        }
    }

    function addButton() {
        if (document.getElementById('customOTPButton')) return; // Prevent duplicate button

        const customButton = document.createElement('button');
        customButton.id = 'customOTPButton';
        customButton.textContent = 'VRChat code';
        customButton.addEventListener('click', extractOTP);

        Object.assign(customButton.style, {
            padding: "10px 15px",
            background: "#4285F4",
            color: "#fff",
            border: "none",
            borderRadius: "5px",
            cursor: "pointer"
        });

        const buttonParent = document.querySelector('.bGJ') || document.querySelector('.aeH');
        if (buttonParent) buttonParent.appendChild(customButton);
    }

    window.addEventListener("load", () => setTimeout(addButton, 1000));
})();