I'm trying to get Tampermonkey to complete an online form.
It works every 1 out of 4 times, all I want it to do is a simple check out process on a bigcartel store. Can anyone help?
It should work on any shop using their platform as they are all quite generic, i.e http://groundup.bigcartel.com
my code;
// ==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();
There are four major issues with your TM script.
1.) Your include tags use https instead of http
2.) document.getElementByName doesn't exist.
Fix: Use document.getElementsByName("checkout")[0]
3.) Once you click the checkout button, the script immediately try to set the values of the input fields, you must wait for the page to load.
4.) document.getElementByType doesn't exist either.
Here is the working script:
// ==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();
}
Related
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 = 'my#email.com'
Important note: this is my first contact with JavaScript and Tampermonkey.
How to make such a script properly?
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 = 'my#email.com'
}, 10000);
Take a look at this code.
I want to get resources from a local file which is, for example, 1.txt and print the content of it in a console log
this code print the content but I want every time I change the content of the file (1.txt) and save it, it changes without making a refresh to the web page
so I'm wondering if you can modify the code to do what I want or is there another way with different code
Thanks
// ==UserScript==
// #name test
// #namespace http://tampermonkey.net/
// #version 1.0.0.1
// #description you
// #author You
// #match https://www.google.com/
// #grant GM_getResourceText
// #resource a file://C:/FORM/1.txt
// ==/UserScript==
function test() {
var b = GM_getResourceText('a')
console.log(b)
}
var stopconsubmit = setInterval(test, 1*1000);
I'm trying to build a script that will click 3 buttons in succession but after clicking the first button, the script goes into infinite reloading.
The site I'm trying to click buttons on: JDoodle
You need to sign-in to see the buttons.
As you can see in the screenshots:
Button 1
Button 2
// ==UserScript==
// #name New Userscript
// #namespace http://tampermonkey.net/
// #version 0.1
// #description try to take over the world!
// #author You
// #match *.jdoodle.com/*
// #grant none
// ==/UserScript==
'use strict';
$ = jQuery;
$(document).ready(function foo(){
var node = document.querySelectorAll('a');
node[8].click(); //clicking button 1
node = document.querySelector('[title="User\'s Saved Files"]');
node.click(); //clicking button 2
}
);
Tried approaches:
1.
unsafeWindow.r=0
if(unsafeWindow.r==0){
foo = function(){};
unsafeWindow.r=1;
}
Result : unsafeWindow.r not defined
2.
f = 1;
while(f){
if(document.querySelector('[title="User\'s Saved Files"]'))
f=0;
}
Result: Infinite reloading.
Simply executing without approaches 1 & 2, no button is being clicked on by the script.
document.querySelector('div.su-input-group:nth-child(2) > input:nth-child(2)').value = ('abc');
document.querySelector("#password").value = "abc";
document.querySelector("#dob").value = "abc";
document.querySelector(".button-orange").click();
So far this is the code that I was able to write and it does not work on https://kite3.zerodha.com/. The script fails after line number 3. BTW same code works for me on other sites.
The reason this code is not working on kite3 website is that controls that need to be filled are animated, and they are not available for selection until animation finishes.
Solution for this is usage of waitForKeyElements js library. When these elements become available values can be set, buttons clicked.
Only one criteria is used for wait just to prove the concept.
This code is working for login on that website, just replace username and password with correct values.
// ==UserScript==
// #name Login to Kite
// #namespace http://tampermonkey.net/
// #version 0.1
// #match *kite3.zerodha.com
// #require https://gist.github.com/raw/2625891/waitForKeyElements.js
// #require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
waitForKeyElements(":password", login);
function login() {
document.querySelector("[type=text]").value = 'yourUserId';
document.querySelector("[type=password]").value = 'yourPassword';
document.querySelector("button").click();
}
I want to submit the form using javascript..
I have tried the codes below but they didn't work, the page just continue refreshing or did nothing.
document.forms[0].submit();
document.forms["create-discussion"].submit();
document.getElementByID("submitButton").click();
document.getElementByID("submitButton").submit();
Please here is the process to access to the webform
1st - www.yookos.com(login page) -- username(tolodo) password(loveworld)
2nd - https://www.yookos.com/discussion/create.jspa?containerID=5460&containerType=700
My Userscript Below fills in text but I still can't get it to submit
// ==UserScript==
// #name discussioncrap code
// #namespace http://hayageek.com
// #include http://www.yookos.*
// #require http://code.jquery.com/jquery-latest.js
// #include https://www.yookos.com/discussion/create.jspa?containerID=5460&containerType=700
// #version 1
// ==/UserScript==
var discussSubj = document.getElementById("subject");
discussSubj.value = "okay";
var discussBody = document.getElementById("wysiwygtext");
discussBody.value = "Just Now";
document.getElementByID("submitButton").click();
Be careful about the fact that javascript is case-sensitive.
In the last line of your code, you use an undefined function: it should be document.getElementById(), not document.getElementByID().