Conversaciones » Peticiones de scripts
Can anyone help me>?
First of all, be sure that your
@include
statement points to a valid url include statement (nothttp://****
). [1]For better performance and readability, do not repeat the same code. Use:
var x = document.getElementsByClassName("cl")[2].innerHTML; x = x.trim(); var elem = document.getElementsByClassName("textBoxDashed app_field"); if(x == "Applicant's Given Name") elem[0].value = 1; else if(x == "Birth Place") elem[0].value = 2; // ... etc.
maxlength
andsize
are element attributes. You should set the value with functionelement.setAttribute("name", "value")
. [2]var elem = document.getElementsByClassName("textBoxDashed app_field"); elem[0].setAttribute("maxlength", 30); elem[0].setAttribute("size", 40); elem[1].setAttribute("maxlength", 30); elem[1].setAttribute("size", 40);
Note that elem declaration is re-used from last point. You only need one.
getElementsByClassName("textBoxDashed app_field")
selects elements with both classes "textBoxDashed" AND "app_field". Be sure you want this. [3]element.innerHTML
returns ALL sub-elements inside the element, not only text. i.e. With<div class="main"><b>Bold</b> text</div>
structure,main.innerHTML
returns "<b>Bold</b> text". [4] Usemain.textContent
to get only the text part; "Bold text". [5] Check what version do you need. If not sure, usetextContent
because you are using string comparations in the code.
You can learn more javascript here: http://www.w3schools.com/js/default.asp
Note: Why are you using @require
jQuery library if you dont use it ?
Can anyone help me>?
I am new with GM and want below script to work. Can any one tell me what I am missing?
// ==UserScript==
// @name Auto Name
// @include http://****
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @version 1
// @grant none
// ==/UserScript==
document.getElementsByClassName("textBoxDashed app_field")[0], maxlength="30";
document.getElementsByClassName("textBoxDashed app_field")[0], size="40";
document.getElementsByClassName("textBoxDashed app_field")[1], maxlength="30";
document.getElementsByClassName("textBoxDashed app_field")[1], size="40";
var x=document.getElementsByClassName("cl")[2].innerHTML;
if (x.trim()=="Applicant's Given Name"){
document.getElementsByClassName("textBoxDashed app_field")[0].value = "GivenName";
}else if (x.trim()=="Birth Place"){
document.getElementsByClassName("textBoxDashed app_field")[0].value = "BirthPlace";
}else if (x.trim()=="Father's Name"){
document.getElementsByClassName("textBoxDashed app_field")[0].value = "FathersName";
}else if (x.trim()=="Mother's Name"){
document.getElementsByClassName("textBoxDashed app_field")[0].value = "MothersName";
}
var y=document.getElementsByClassName("cl")[3].innerHTML;
if (y.trim() =="Applicant's Given Name"){
document.getElementsByClassName("textBoxDashed app_field")[1].value = "GivenName";
}else if (y.trim()=="Birth Place"){
document.getElementsByClassName("textBoxDashed app_field")[1].value = "BirthPlace";
}else if (y.trim()=="Father's Name"){
document.getElementsByClassName("textBoxDashed app_field")[1].value = "FathersName";
}else if (y.trim()=="Mother's Name"){
document.getElementsByClassName("textBoxDashed app_field")[1].value = "MothersName";
}