Is there a way to ignore integers in a bookmarklet?
Problem Description:
I used https://formfillerjs.com/ to create a bookmarklet. It works although, there is one problem, the bookmarklet only works once due to the value of the password box changing when the website is refreshed. When visiting the website, the password box’s value is ember
with a random 3 digits behind of it. (ex. ember321
)
If I click on the bookmarklet, I want it to fill the boxes on the website with my username and password. When I click on it now, the username gets filled in because the value of the username box doesn’t change unlike the password box which changes on refresh or when I leave and visit the website again.
Bookmarklet:
javascript:/* FormFiller v0.2.0 */var d=document;function i(a){return d.getElementById(a)}function n(a){return d.getElementsByName(a)[0]}function e(a){t='change';if(window.navigator.userAgent.match(/Trident|MSIEs/g)!=null){x=d.createEvent('Events');x.initEvent(t,1,0);}else{x=new Event(t);}a.dispatchEvent(x);}function v(a,v){a.value=v;e(a)}function c(a){a.checked=true;e(a)}v(i("identification"),"UsernameForLogin");v(i("ember479"),"PasswordForLogin");void(0);
Javascript:
var d = document;
function i(a) {
return d.getElementById(a)
}
function n(a) {
return d.getElementsByName(a)[0]
}
function e(a) {
t = 'change';
if (window.navigator.userAgent.match(/Trident|MSIEs/g) != null) {
x = d.createEvent('Events');
x.initEvent(t, 1, 0);
} else {
x = new Event(t);
}
a.dispatchEvent(x);
}
function v(a, v) {
a.value = v;
e(a)
}
function c(a) {
a.checked = true;
e(a)
}
v(i("identification"), "UsernameForLogin");
v(i("ember479"), "PasswordForLogin");
void(0);
Solution – 1
let’s update this a bit:
// let's replace all these:
/*
var d = document;
outdated/unnecessary, ...
function i(a) {
return d.getElementById(a)
}
function n(a) {
return d.getElementsByName(a)[0]
}
*/
// with this one:
function qs(s) {
return document.querySelector(s)
}
function e(a) {
// IE's finally dead.
/*
t = 'change';
if (window.navigator.userAgent.match(/Trident|MSIEs/g) != null) {
x = d.createEvent('Events');
x.initEvent(t, 1, 0);
} else {
x = new Event(t);
}
a.dispatchEvent(x);
*/
a.dispatchEvent(new Event("change"));
}
function v(a, v) {
a.value = v;
e(a)
}
// You're not checking any boxes
/*
function c(a) {
a.checked = true;
e(a)
}
*/
v(qs("#identification"), "UsernameForLogin");
// and now we can look for an <input> who's id starts with "ember"
v(qs("input[id^=ember]"), "PasswordForLogin");
void(0);
or short
function qs(s) { return document.querySelector(s) }
function v(a, v) { a.value = v; a.dispatchEvent(new Event("change")); }
v(qs("#identification"), "UsernameForLogin");
v(qs("input[id^=ember]"), "PasswordForLogin");
void(0);