2017-12-04 15 views
0

私はTampermonkeyにオンラインフォームを完成させようとしています。 4回に1回ずつ動作します。私がしたいのは、bigcartelストアでの簡単なチェックアウトプロセスだけです。誰も助けることができますか?彼らはすべての非常に一般的なものとして、それは彼らのプラットフォームを使用して任意の店で動作するはずですTampermonkeyスクリプトは散発的にしか動作しませんか?

、すなわち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 = "[email protected]"; 

// click "next" button 
document.getElementByType("submit").click(); 

答えて

1

TMスクリプトには4つの大きな問題があります。

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 = "[email protected]"; 
    // click "next" button 
    document.getElementsByTagName("button")[0].click(); 
} 
+1

これは完璧に動作します – oversoon

関連する問題