【问题标题】:Why doesn't my Tampermonkey script run on some particular websites为什么我的 Tampermonkey 脚本不能在某些特定网站上运行
【发布时间】:2022-07-06 04:39:29
【问题描述】:

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

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

【问题讨论】:

标签: javascript html tampermonkey userscripts


【解决方案1】:

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

  • 如果您的脚本正在运行,但在完全运行之前遇到错误。如果是这样,我会看看其他社区成员提出的solutions
  • 如果您的脚本确实根本无法运行,请检查您的 Tampermonkey 或浏览器设置

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

【讨论】:

    猜你喜欢
    • 2018-10-08
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    相关资源
    最近更新 更多