ChatGPT OTP Auto-Fill

A new extension

Size

3.1 KB

Version

1.0.1

Created

Apr 2, 2026

Updated

14 days ago

1// ==UserScript==
2// @name		ChatGPT OTP Auto-Fill
3// @description		A new extension
4// @version		1.0.1
5// @match		https://*.chatgpt.com/*
6// @icon		https://chatgpt.com/favicon.ico
7// ==/UserScript==
8(function() {
9    'use strict';
10
11    // Function to detect and fill OTP fields
12    function detectAndFillOTP() {
13        // Look for input fields that might be OTP fields
14        const otpInputs = document.querySelectorAll('input[type="text"], input[type="number"], input[name*="otp"], input[name*="code"], input[placeholder*="code"], input[placeholder*="OTP"]');
15        
16        otpInputs.forEach(input => {
17            // Check if the input is likely an OTP field based on attributes
18            if (input.name.toLowerCase().includes('otp') || 
19                input.name.toLowerCase().includes('code') || 
20                input.placeholder.toLowerCase().includes('code') || 
21                input.placeholder.toLowerCase().includes('otp') ||
22                input.maxLength === 6) { // Common OTP length
23                
24                // Try to get OTP from clipboard
25                navigator.clipboard.readText().then(text => {
26                    // Check if clipboard content looks like an OTP (6 digits)
27                    if (/^\d{6}$/.test(text)) {
28                        input.value = text;
29                        // Dispatch input and change events to notify the page of the change
30                        input.dispatchEvent(new Event('input', { bubbles: true }));
31                        input.dispatchEvent(new Event('change', { bubbles: true }));
32                        console.log('OTP Auto-Fill: Successfully filled OTP field with clipboard content');
33                    }
34                }).catch(err => {
35                    console.log('OTP Auto-Fill: Could not access clipboard -', err);
36                });
37            }
38        });
39    }
40
41    // Run detection immediately when the script loads
42    detectAndFillOTP();
43
44    // Set up a MutationObserver to watch for new OTP fields that might be added dynamically
45    const observer = new MutationObserver(mutations => {
46        mutations.forEach(mutation => {
47            if (mutation.type === 'childList') {
48                mutation.addedNodes.forEach(node => {
49                    if (node.nodeType === Node.ELEMENT_NODE) {
50                        // Check if the added node itself is an OTP field
51                        if ((node.tagName === 'INPUT' && 
52                             (node.name.toLowerCase().includes('otp') || 
53                              node.name.toLowerCase().includes('code') || 
54                              node.placeholder.toLowerCase().includes('code') || 
55                              node.placeholder.toLowerCase().includes('otp'))) ||
56                            node.querySelectorAll) {
57                            detectAndFillOTP();
58                        }
59                    }
60                });
61            }
62        });
63    });
64
65    // Start observing the document body for changes
66    observer.observe(document.body, {
67        childList: true,
68        subtree: true
69    });
70
71    // Also check periodically in case the above methods miss anything
72    setInterval(detectAndFillOTP, 2000);
73
74})();