简体   繁体   中英

Why doesn't my Tampermonkey script run on some particular websites

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...
})();

In my experience it's usually a problem with timing (waiting for the page to completely load before running the script). I'd take a closer look at:

  • if your script is running, but coming across an error before being able to run entirely. If so, I'd take a look at solutions that other community members have come up with.
  • if your script really doesn't run at all , maybe check your tampermonkey or browser settings

at the very leaast, by debugging the above, you can come up with a better idea on the source of the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM