🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/06 06:42:04
🔄 下次更新时间:2026/01/06 07:42:04
手动刷新缓存

Sora Auto Code Generator by robomonkey.io

Automatically generates and submits invite codes for Sora

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

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

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

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

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

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

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

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

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

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

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

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

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

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

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

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name		Sora Auto Code Generator by robomonkey.io
// @description		Automatically generates and submits invite codes for Sora
// @author Robomonkey
// @version		1.1.2
// @match		https://*.sora.chatgpt.com/*
// @icon		https://cdn.openai.com/sora/assets/favicon-dark.ico
// @license MIT
// @namespace https://greasyfork.org/users/1521443
// ==/UserScript==
(function() {
    'use strict';

    function init() {
        console.log('Sora Auto Code Generator initialized');
        
        // Wait for the dialog to appear
        const observer = new MutationObserver(() => {
            const dialog = document.querySelector('[role="dialog"][aria-labelledby*="radix"]');
            const heading = document.querySelector('h2.font-brand');
            
            if (dialog && heading && heading.textContent.includes('Enter invite code')) {
                addGenerateButton();
                observer.disconnect();
            }
        });
        
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
        
        // Check if dialog is already present
        const existingDialog = document.querySelector('[role="dialog"][aria-labelledby*="radix"]');
        const existingHeading = document.querySelector('h2.font-brand');
        if (existingDialog && existingHeading && existingHeading.textContent.includes('Enter invite code')) {
            addGenerateButton();
        }
    }

    function addGenerateButton() {
        // Check if button already exists
        if (document.getElementById('auto-code-generator-btn')) {
            return;
        }

        console.log('Adding generate code button');
        
        // Find the container with the input slots
        const inputContainer = document.querySelector('[data-input-otp-container="true"]');
        if (!inputContainer) {
            console.error('Could not find input container');
            return;
        }

        // Create the button
        const button = document.createElement('button');
        button.id = 'auto-code-generator-btn';
        button.textContent = 'Generate & Submit Code';
        button.style.cssText = `
            margin-top: 16px;
            padding: 12px 24px;
            background: linear-gradient(to bottom, #1a73e8, #0d47a1);
            color: white;
            border: none;
            border-radius: 9999px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        `;
        
        button.addEventListener('mouseenter', () => {
            button.style.background = 'linear-gradient(to bottom, #1557b0, #0a3a82)';
            button.style.transform = 'scale(1.02)';
        });
        
        button.addEventListener('mouseleave', () => {
            button.style.background = 'linear-gradient(to bottom, #1a73e8, #0d47a1)';
            button.style.transform = 'scale(1)';
        });
        
        button.addEventListener('click', async () => {
            console.log('Generate button clicked');
            await generateAndSubmitCode();
        });

        // Insert button after the input container
        inputContainer.parentElement.appendChild(button);
        console.log('Button added successfully');
    }

    function generateRandomCode() {
        const characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        let code = '';
        for (let i = 0; i < 6; i++) {
            const randomIndex = Math.floor(Math.random() * characters.length);
            code += characters[randomIndex];
        }
        console.log('Generated code:', code);
        return code;
    }

    async function generateAndSubmitCode() {
        const code = generateRandomCode();
        
        // Find the hidden input field
        const hiddenInput = document.querySelector('input[data-slot="input-otp"]');
        if (!hiddenInput) {
            console.error('Could not find input field');
            return;
        }

        console.log('Filling code into input field');
        
        // Set the value
        hiddenInput.value = code;
        
        // Trigger input events to make the UI update
        hiddenInput.dispatchEvent(new Event('input', { bubbles: true }));
        hiddenInput.dispatchEvent(new Event('change', { bubbles: true }));
        
        // Wait a moment for the UI to update
        await new Promise(resolve => setTimeout(resolve, 500));
        
        // Find the submit button inside the dialog (not the fixed floating one)
        const dialog = document.querySelector('[role="dialog"]');
        if (!dialog) {
            console.error('Could not find dialog');
            return;
        }
        
        const buttons = Array.from(dialog.querySelectorAll('button'));
        const submitButton = buttons.find(btn => btn.textContent.includes('Join New Sora'));
        
        if (submitButton) {
            console.log('Clicking submit button inside dialog');
            // Trigger multiple events to ensure the click is registered
            submitButton.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
            submitButton.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
            submitButton.click();
            submitButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
        } else {
            console.error('Could not find submit button in dialog');
        }
    }

    // Initialize when page loads
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();