[英]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...
})();
以我的经验,这通常是时间问题(在运行脚本之前等待页面完全加载)。 我会仔细看看:
至少,通过调试上述内容,您可以更好地了解问题的根源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.