trying to auto-login at https://kite3.zerodha.com/ using javascript GreaseMonkey - javascript

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

Related

Tampermonkey script is probably executed at the wrong time

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);

how i can get resources from a local files with tampermonkey without making a refresh to the web page?

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);

Tampermonkey script only sporadically working?

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

Unable to retrieve AJAXed content

I am unable to retrieve a username from a dynamic webpage using the wait function. However when I execute $("#label301354000").text(); in Chrome Developer tool, I get my username. Any idea how to tweak the function to capture the id value?
// ==UserScript==
// #name UI
// #namespace http://tampermonkey.net/
// #version 0.1
// #description Test
// #author Dejan
// #match http://url/*
// #require https://ajax.googleapis.com/ajax/libs/jquery/2.2.0
// #require https://gist.githubusercontent.com/raw/2625891/waitForKeyElements.js
// #grant GM_addStyle
// ==/UserScript==
/* jshint -W097 */
'use strict';
waitForKeyElements("#label301354000", getUser);
function getUser(jNode) {
console.log("User is "+ jNode.text() );
}
The question omits critical details, see the comments above.
But in general, if $("#label301354000").text(); always works and
function getUser(jNode) {
console.log("User is "+ jNode.text() );
}
Comes up empty in the Tampermonkey script, it suggests that the target node is not the best choice or that the node is created at some point and filled in by the page later.
waitForKeyElements checks the callback return for cases like that. Change getUser() to:
function getUser(jNode) {
var usrText = jNode.text ().trim ();
if (usrText) {
console.log ("User is " + usrText);
}
else
return true; //-- Keep waiting.
}
If that doesn't work, provide a proper MCVE and/or link to the target page. (Per SO guidelines, you should always provide one or both.)

I Want To Click Post Button On This WebPage

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().

Categories

Resources