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

发布于 2025-02-13 04:26:59 字数 1616 浏览 0 评论 0原文

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

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

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

// ==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',"[email protected]");
    document.getElementsByClassName('text-box__input')[1].setAttribute("id","passworde");
    replaceValue('#passworde',"MyPASsword123!")


     }
    'use strict';

    // Your code here...
})();

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',"[email protected]");
    document.getElementsByClassName('text-box__input')[1].setAttribute("id","passworde");
    replaceValue('#passworde',"MyPASsword123!")


     }
    'use strict';

    // Your code here...
})();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一江春梦 2025-02-20 04:26:59

我遇到了一个类似的问题,脚本根本没有运行。
问题是开发人员模式未在Google Chrome中启用。

这在Tampermonkey常见问题中提到: https:///www.tampermonkey.net/faq.phppt Q407

I was having a similar issue where the script was not running at all.
The issue was that the Developer Mode was not enabled in Google Chrome.

This is mentioned in the Tampermonkey FAQ: https://www.tampermonkey.net/faq.php#Q407

阪姬 2025-02-20 04:26:59

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

  • 如果您的脚本正在运行,但是在能够完全运行之前遇到了错误。如果是这样,我会看一下解决方案其他社区成员提出了。
  • 如果您的脚本确实根本无法运行 ,也可以

通过调试上述来检查您的Tampermonkey或浏览器设置,您可以在问题来源中提出一个更好的想法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文