TampermonKey脚本可能在错误的时间执行
我想制作一个脚本来填写 Doulos 网络研讨会的注册表。例如 https://register.gotowebinar.com/register/2965111702634965004
当我转到此链接时通过 Firefox 它会加载 https://register.gotowebinar.com/pageNotFound
只有当我点击返回时,才会出现正确的表单。看起来 tampermonkey 试图在脚本到达正确的表单之前运行脚本,它在那里找不到正确的字段,在这种情况下,一旦加载脚本中指示的字段就不会被填写。
这里有一个例子,如果我想要的话来填补名字和电子邮件:
// ==UserScript==
// @name Duolos autofill registration form
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author blaz
// @match https://register.gotowebinar.com/register/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gotowebinar.com
// @grant none
// @run-at document-end
// ==/UserScript==
var formFirstName = document.getElementById('registrant.firstName')
var formEmail = document.getElementById('registrant.email')
formFirstName.value = 'My_first_name'
formEmail.value = '[email protected]'
重要提示:这是我第一次接触 JavaScript 和 Tampermonkey。
如何正确制作这样的脚本?
I want to make a script that fills the registration form for Doulos webinars. e.g. https://register.gotowebinar.com/register/2965111702634965004
When I go to this link via Firefox it loads https://register.gotowebinar.com/pageNotFound
Only when I click back then the proper form comes in. It looks like tampermonkey is trying to run the script before it gets to the right form, it doesn't find the right fields there and in this situation once it loads the fields indicated in the script are not filled in.
Here an example if I wanted to fill the first name and email:
// ==UserScript==
// @name Duolos autofill registration form
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author blaz
// @match https://register.gotowebinar.com/register/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gotowebinar.com
// @grant none
// @run-at document-end
// ==/UserScript==
var formFirstName = document.getElementById('registrant.firstName')
var formEmail = document.getElementById('registrant.email')
formFirstName.value = 'My_first_name'
formEmail.value = '[email protected]'
Important note: this is my first contact with JavaScript and Tampermonkey.
How to make such a script properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
continue
Filling works as I applied the suggested setTimeout() by @JeremyThille
I keep up with clicking on 'Undo' within 10 seconds and the form loads during that time.