Attempting to populate a form on a client's website with data from our database using a Greasemonkey script, but struggling with the same origin policy.
I have tried using GM_xmlhttpRequest and even specified @grant GM_xmlhttpRequest but without success.
Here is my script. What am I missing?
// ==UserScript==
// @name ORL Prepop Test
// @namespace customertrackinc.com
// @description Prepopulate ORL Fields
// @include https://www.openroadlending.com/Apply.aspx*
// @version 1
// @grant GM_xmlhttpRequest
// ==/UserScript==
document.body.style.background = "white";
document.getElementById('ctl00_TopMenu_T872C6B14002_Menu1').innerHTML = "";
document.getElementById('Header').style.background = "#968888";
document.getElementById('Header').style.color = "black";
document.getElementById('Header').style.backgroundRepeat = "no-repeat";
document.getElementById('Header').style.backgroundPosition="bottom left";
document.getElementById('Header').style.border = "1px solid black";
document.getElementById('Header').style.padding = "1em";
document.getElementById('SuperLinks').innerHTML = "";
document.getElementById('SideBar').innerHTML = "";
document.getElementById('Logo').innerHTML = "";
document.getElementById('TagLine').innerHTML = "";
document.getElementById('LP_DIV_1368197056862').style.display = "none";
document.getElementById('Header').innerHTML = '<div style="position:absolute; bottom:0; left:0; padding:.5em;">Script is working so far...</div>';
var boxes = document.getElementsByClassName('sfContentBlock'),
i = boxes.length;
while(i--) {
boxes[i].style.display = "none;";
}
var all=document.getElementsByTagName("h1");
for (var i=0, max=all.length; i < max; i++) {
all[i].style.display = "none";
}
var all=document.getElementsByTagName("h2");
for (var i=0, max=all.length; i < max; i++) {
all[i].style.display = "none";
}
function addEventHandler(elem,eventType,handler) {
if (elem.addEventListener)
elem.addEventListener (eventType,handler,false);
else if (elem.attachEvent)
elem.attachEvent ('on'+eventType,handler);
}
function startAjax(){
var param1ct = document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1').value;
var param2ct = document.getElementById('BodyContent_ctl00_ctl00_txtLastName1').value;
var param3ct = document.getElementById('BodyContent_ctl00_ctl00_txtStreetAddress1').value;
var urlct = "URL INTENTIONALLY OMITTED/ajaxhandler.php?fname="+param1ct+"&lname"+param2ct+"&addr"+param3ct;
GM_xmlhttpRequest({
method: "GET",
url: urlct,
onload: function(response) {
var statusct = xmlhttpp.responseXML.getElementsByTagName('status')[0].firstChild.nodeValue;
var fnamect = xmlhttpp.responseXML.getElementsByTagName('fname')[0].firstChild.nodeValue;
var addrct = xmlhttpp.responseXML.getElementsByTagName('addr')[0].firstChild.nodeValue;
var lnamect = xmlhttpp.responseXML.getElementsByTagName('lname')[0].firstChild.nodeValue;
var cityct = xmlhttpp.responseXML.getElementsByTagName('city')[0].firstChild.nodeValue;
var statect = xmlhttpp.responseXML.getElementsByTagName('street')[0].firstChild.nodeValue;
var zipct = xmlhttpp.responseXML.getElementsByTagName('zip')[0].firstChild.nodeValue;
var emailct = xmlhttpp.responseXML.getElementsByTagName('email')[0].firstChild.nodeValue;
document.getElementById("Header").innerHTML=statusct;
if(status == "Bingo"){
var confirmMsg = "*User Found*\n\nName: "+fnamect+" "+lnamect+"\nAddress: "+addrct+"\nCity: "+cityct+"\nState: "+statect+"\nZip: "+zipct+"\nEmail: "+emailct+"\n\nClick 'OK' To populate fields or click 'Cancel' if this is not the correct info.";
var fillOrNot = confirm(confirmMsg);
if(fillOrNot === true){
document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1').value = fnamect;
document.getElementById('BodyContent_ctl00_ctl00_txtLastName1').value = lnamect;
document.getElementById('BodyContent_ctl00_ctl00_txtStreetAddress1').value = addrct;
}else{
document.getElementById("Header").innerHTML="Aborted";
}
}
}
});
}
var first_name_field = document.getElementById('BodyContent_ctl00_ctl00_txtFirstName1');
addEventHandler(first_name_field,"keyup",startAjax);