Please help me, how to detect if the values are the same or not? I have a script that automatically open a new browser tab for Google Maps and search the detected home address. But, what if there's a two different address? How to detect it? I have two types of home address, one is contact address and second, permanent address. There's a time that those types of address have different values. If permanent address is detect that have a different values it will open a new separate browser tab for Google Maps. In short, if the two types of home address are both different in each other, it will open two Google Maps. One for Contact and one for Permanent. Please help me. Thank you
Here's the script of detecting of address:
function scanLapVerification() {
try {
//check if the page is activity where address check is done
var page_title = "Title";
var el = getElement(document, "class", "view-operator-verification-title", "");
if (!el || el.length == 0) return;
if (el[0].innerText != page_title) return;
var page_title = '';
var el = getElement(document, "class", "workflowActivityDetailPanel", "");
if (el && el.length > 0) {
var eltr = getElement(el[0], "tag", "tr", "");
if (eltr && eltr.length > 0) {
//Read Contact and Permanent address
var addresses = {
CA: { province: null, municipality: null, barangay: null, zip: null, street: null, snumber: null, building: null, floor: null }
,PA: { province: null, municipality: null, barangay: null, zip: null, street: null, building: null, bnumber: null, floor: null }
};
var address_type = null;
for (var i = 0; i < eltr.length; i++) {
tr_text = eltr[i].innerText;
if (tr_text.substr(0, "Contact address".length) == "Contact address") address_type = "CA";
if (tr_text.substr(0, "Permanent address".length) == "Permanent address") address_type = "PA";
if (address_type && tr_text.substr(0, "Province".length) == "Province") {
addresses[address_type].province = tr_text.substr("Province".length + 1, tr_text.length - "Province".length - 1);
}
if (address_type && tr_text.substr(0, "Barangay".length) == "Barangay") {
addresses[address_type].barangay = tr_text.substr("Barangay".length + 1, tr_text.length - "Barangay".length - 1);
}
if (address_type && tr_text.substr(0, "ZIP Code".length) == "ZIP Code") {
addresses[address_type].zip = tr_text.substr("ZIP Code".length, tr_text.length - "ZIP Code".length);
}
if (address_type && tr_text.substr(0, "Street name".length) == "Street name") {
addresses[address_type].street = tr_text.substr("Street name".length, tr_text.length - "Street name".length);
}
}
var contact_address = addresses.CA.street
+ '' + addresses.CA.barangay
+ '' + addresses.CA.province
+ '' + addresses.CA.zip;
contact_address = contact_address.replace(/\s+/g, ' ').trim();
return { content: "address_check", contact_address: contact_address, permanent_address: null };
}
}
return { status: "KO" };
} catch (e) {
alert("Exception: scanLapVerification\n" + e.Description);
return { status: "KO", message: e };
}
};
Here's the script for open a new browser tab:
function scanLapVerification() {
msgbox("sendRequest: scanLapVerification");
chrome.tabs.sendRequest(tabLapVerification, { method: "scanLapVerification" },
function (response) {
msgbox("receiveResponse: scanLapVerification " + jsonToString(response, "JSON"));
// maintaining state in the background
if (response.data.content == "address_check") {
//open google maps with request for contact address
var gmaps;
if (confirm("Do you want to proceed on Google Maps and search for Contact Address?") == true) {
gmaps = tabCreate("http://maps.google.com/maps?q=" + encodeURIComponent(response.data.contact_address));
} else {
gmaps = "You Cancel!";
}
document.getElementById("maps").innerText = gmaps;
}
}
);
}