TampermonKey脚本可能在错误的时间执行

发布于 2025-01-19 01:13:52 字数 1343 浏览 1 评论 0原文

我想制作一个脚本来填写 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 技术交流群。

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

发布评论

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

评论(1

森罗 2025-01-26 01:13:52

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.

setTimeout(function(){
    console.log("10s later...");

    var formFirstName = document.getElementById('registrant.firstName')
    var formEmail = document.getElementById('registrant.email')

    formFirstName.value = 'My_first_name'
    formEmail.value = '[email protected]'

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