0% found this document useful (0 votes)
289 views3 pages

Auto Past Vfs

bobA

Uploaded by

abdel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
289 views3 pages

Auto Past Vfs

bobA

Uploaded by

abdel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// ==UserScript==

// @name OTP Auto Paste and Submit


// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically paste the OTP from the clipboard to a specific input
field and auto-submit
// @match https://online.vfsglobal.dz/Global-Appointment/*
// @grant GM_setClipboard
// ==/UserScript==

(function() {
'use strict';

let stopFunction = false; // Flag to stop function execution


let submitted = false; // Flag to track if submission has occurred

// Function to retrieve OTP from clipboard and paste it into the designated
input field
function pasteOTPFromClipboardAndSubmit() {
if (stopFunction || submitted) return; // Stop execution if flag is set or
submission has occurred

navigator.clipboard.readText().then(clipboardText => {
const otpInput = document.querySelector('input#OTPe');
if (otpInput && clipboardText.trim() !== '') {
const otpRegex = /^\d{6}$/; // Regex to match exactly 6 digits
if (otpRegex.test(clipboardText.trim())) {
otpInput.value = clipboardText.trim(); // Paste OTP from clipboard
console.log('OTP pasted from clipboard:', clipboardText.trim());
clearClipboard(); // Clear the clipboard after OTP is pasted
clickSubmitButton(); // Click the submit button after OTP is pasted
} else {
console.log('Invalid OTP format. OTP must contain exactly 6
digits.');
}
} else {
console.log('No OTP input field found or clipboard is empty.');
}
}).catch(error => {
console.error('Failed to read clipboard:', error);
});
}

// Function to click the submit button


function clickSubmitButton() {
const submitButton = document.querySelector('#txtsub');
if (submitButton) {
submitButton.click(); // Auto-click on the submit button
console.log('Submit button clicked.');
submitted = true; // Set flag to true after submission
} else {
console.log('Submit button not found.');
}

// Auto-click on the "Continue" link


const continueLink = document.querySelector('a.submitbtn[href="/Global-
Appointment/Calendar/FinalCalendar"]');
if (continueLink) {
continueLink.click();
console.log('Continue link clicked.');
} else {
console.log('Continue link not found.');
}
}

// Function to clear the clipboard


function clearClipboard() {
navigator.clipboard.writeText(''); // Write an empty string to clear the
clipboard
console.log('Clipboard cleared.');
}

// Function to stop script execution when challenge stage appears


function stopOnChallengeStage(mutationsList, observer) {
mutationsList.forEach(mutation => {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(node => {
if (node.id === 'challenge-stage') {
stopFunction = true;
}
});
}
});
}

// Create a mutation observer


const observer = new MutationObserver(stopOnChallengeStage);

// Start observing changes in the body


observer.observe(document.body, { childList: true, subtree: true });

// Paste OTP from clipboard and auto-submit every second


setInterval(pasteOTPFromClipboardAndSubmit, 1000);

// Add a button to clear the clipboard


function addClearClipboardButton() {
const headerWrapper = document.querySelector('.header .wrapper');
if (headerWrapper) {
const clearClipboardButton = document.createElement('button');
clearClipboardButton.textContent = 'Clear Clipboard';
clearClipboardButton.style.padding = '5px 9px';
clearClipboardButton.style.border = 'none';
clearClipboardButton.style.borderRadius = '4px';
clearClipboardButton.style.backgroundColor = '#4CAF50';
clearClipboardButton.style.color = 'white';
clearClipboardButton.style.cursor = 'pointer';
clearClipboardButton.style.marginLeft = '3px';
clearClipboardButton.onclick = clearClipboard;
headerWrapper.appendChild(clearClipboardButton);
console.log('Clear clipboard button added.');
} else {
console.log('Header wrapper not found.');
}
}

addClearClipboardButton(); // Call the function to add the clear clipboard


button
})();

You might also like