【发布时间】: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