Tampermonkey脚本只是零星工作?

时间:2017-12-04 21:36:30

标签: javascript tampermonkey

我正在尝试让Tampermonkey完成在线表格。 它每4次中有1次工作,我想要它做的就是在bigcartel商店进行简单的结账过程。有人可以帮忙吗?

它应该适用于任何使用他们平台的商店,因为它们都非常通用,即http://groundup.bigcartel.com

我的代码;

ERROR 1146: Table 'dbo.nametable' doesn't exist

1 个答案:

答案 0 :(得分:1)

您的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();
}