I made some scripts to automatically insert the username and password and press the Log in button for me when I visit websites. On some websites, it is as easy as
document.getElementById('username').value='myname'
document.getElementById('loginButton').click()
And when I visit the website, all those actions will be done instantly. However, on some websites, such as https://login.payoneer.com/, the script doesn't run at all. When I paste the script into the console, it works fine; however, it doesn't automatically run when the page loads. Can someone suggest a way to make the script work? This is my script:
// ==UserScript==
// @name payoneer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://login.payoneer.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=payoneer.com
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
window.onload = function (){
function replaceValue(selector, value) {
const el = document.querySelector(selector);
if (el) {
el.focus();
el.select();
if (!document.execCommand('insertText', false, value)) {
// Fallback for Firefox: just replace the value
el.value = 'new text';
}
el.dispatchEvent(new Event('change', {bubbles: true})); // usually not needed
}
return el;
}
replaceValue('#username',"myUsername@gmail.com");
document.getElementsByClassName('text-box__input')[1].setAttribute("id","passworde");
replaceValue('#passworde',"MyPASsword123!")
}
'use strict';
// Your code here...
})();