Tampermonkey 脚本只能偶尔工作?
Tampermonkey script only sporadically working?
我正在尝试让 Tampermonkey 完成在线表格。
它每 4 次工作一次,我想要它做的只是在 bigcartel 商店上进行一个简单的结帐过程。有人可以帮忙吗?
它应该适用于任何使用他们平台的商店,因为它们都很通用,即 http://groundup.bigcartel.com
我的代码;
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://checkout.bigcartel.com/*
// @include https://*.bigcartel.com/product
// @include https://*.bigcartel.com/cart
// @grant none
// ==/UserScript==
// on "/cart" page click checkout button
document.getElementByName("checkout").click();
// fill first three form fields
document.getElementById("buyer_first_name").value = "John";
document.getElementById("buyer_last_name").value = "Smith";
document.getElementById("buyer_email").value = "john@doe.com";
// click "next" button
document.getElementByType("submit").click();
您的 TM 脚本存在四个主要问题。
1.) 您的包含标签使用 https
而不是 http
2.) document.getElementByName
不存在。
修正:使用document.getElementsByName("checkout")[0]
3.) 一旦点击 checkout
按钮,脚本会立即尝试设置输入字段的值,您必须等待页面加载。
4.) document.getElementByType
也不存在
这是工作脚本:
// ==UserScript==
// @name Script
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://checkout.bigcartel.com/*
// @include http://*.bigcartel.com/product
// @include http://*.bigcartel.com/cart
// @grant none
// ==/UserScript==
// on "/cart" page click checkout button
if (window.location.origin !== "https://checkout.bigcartel.com") document.getElementsByName("checkout")[0].click();
else {
// fill first three form fields
document.getElementById("buyer_first_name").value = "John";
document.getElementById("buyer_last_name").value = "Smith";
document.getElementById("buyer_email").value = "john@doe.com";
// click "next" button
document.getElementsByTagName("button")[0].click();
}
我正在尝试让 Tampermonkey 完成在线表格。 它每 4 次工作一次,我想要它做的只是在 bigcartel 商店上进行一个简单的结帐过程。有人可以帮忙吗?
它应该适用于任何使用他们平台的商店,因为它们都很通用,即 http://groundup.bigcartel.com
我的代码;
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://checkout.bigcartel.com/*
// @include https://*.bigcartel.com/product
// @include https://*.bigcartel.com/cart
// @grant none
// ==/UserScript==
// on "/cart" page click checkout button
document.getElementByName("checkout").click();
// fill first three form fields
document.getElementById("buyer_first_name").value = "John";
document.getElementById("buyer_last_name").value = "Smith";
document.getElementById("buyer_email").value = "john@doe.com";
// click "next" button
document.getElementByType("submit").click();
您的 TM 脚本存在四个主要问题。
1.) 您的包含标签使用 https
而不是 http
2.) document.getElementByName
不存在。
修正:使用document.getElementsByName("checkout")[0]
3.) 一旦点击 checkout
按钮,脚本会立即尝试设置输入字段的值,您必须等待页面加载。
4.) document.getElementByType
也不存在
这是工作脚本:
// ==UserScript==
// @name Script
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://checkout.bigcartel.com/*
// @include http://*.bigcartel.com/product
// @include http://*.bigcartel.com/cart
// @grant none
// ==/UserScript==
// on "/cart" page click checkout button
if (window.location.origin !== "https://checkout.bigcartel.com") document.getElementsByName("checkout")[0].click();
else {
// fill first three form fields
document.getElementById("buyer_first_name").value = "John";
document.getElementById("buyer_last_name").value = "Smith";
document.getElementById("buyer_email").value = "john@doe.com";
// click "next" button
document.getElementsByTagName("button")[0].click();
}