繁体   English   中英

为什么我的 Tampermonkey 脚本不能在某些特定网站上运行

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

我制作了一些脚本来自动插入用户名和密码,并在我访问网站时为我按下登录按钮。 在某些网站上,它就像

document.getElementById('username').value='myname'
document.getElementById('loginButton').click()

当我访问该网站时,所有这些操作都会立即完成。 但是,在某些网站上,例如https://login.payoneer.com/ ,脚本根本不运行。 当我将脚本粘贴到控制台时,它工作正常; 但是,它不会在页面加载时自动运行。 有人可以建议一种使脚本正常工作的方法吗? 这是我的脚本:

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

以我的经验,这通常是时间问题(在运行脚本之前等待页面完全加载)。 我会仔细看看:

  • 如果您的脚本正在运行,但在能够完全运行之前遇到错误。 如果是这样,我会看看其他社区成员提出的解决方案
  • 如果你的脚本真的根本没有运行,也许检查你的 Tampermonkey 或浏览器设置

至少,通过调试上述内容,您可以更好地了解问题的根源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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