-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
75 lines (57 loc) · 2.6 KB
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
localStorage.setItem('alerted','no');
localStorage.setItem('flag', 'unset');
console.log("Script starting...");
setInterval(function() { //Loop script every 3 seconds
console.log("Content script looping...");
/* Retrieve the pincode, suburb/city */
var pinCode = document.getElementById('ctl00_NewOrderControlModal_ContactEdit_Destination_RadComboBox_PostCode_Input').value;
var suburb = document.getElementById('ctl00_NewOrderControlModal_ContactEdit_Destination_RadComboBox_Suburb_Input').value.toUpperCase();
var city = document.getElementById('ctl00_NewOrderControlModal_ContactEdit_Destination_TextBox_City').value.toUpperCase();
if (pinCode == "") {
localStorage.setItem('flag', 'unset');
}
if (pinCode != "") {
if ( (localStorage.getItem('flag') || '') != 'set') {
if (pinCode == localStorage.getItem('alerted') || '')
{
localStorage.setItem('flag', 'set');
const url = chrome.runtime.getURL('data/tolllist.json');
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var json = JSON.parse(this.response);
json.forEach((item) => {
if ((item.Pincode == pinCode) && ((item.Name.toUpperCase() == suburb) || (item.Name.toUpperCase() == city)))
{
var alerted = localStorage.getItem('alerted') || '';
console.log("ALERTED: "+ alerted);
alert("Toll RA surcharge! Suburb: " + item.Name + " | Cost: $" +item.Cost);
localStorage.setItem('alerted', item.Pincode);
}
});
};
xhr.open('GET', chrome.extension.getURL('data/tolllist.json'), true);
xhr.send();
}
}
}
/////////////////////////////
console.log("The pin, suburb, city : "+ pinCode +" "+ suburb + " " +city);
const url = chrome.runtime.getURL('data/tolllist.json');
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var json = JSON.parse(this.response);
json.forEach((item) => {
if ((item.Pincode == pinCode) && ((item.Name.toUpperCase() == suburb) || (item.Name.toUpperCase() == city)))
{
var alerted = localStorage.getItem('alerted') || '';
console.log("ALERTED: "+ alerted);
if (alerted != item.Pincode) {
alert("Toll RA surcharge! Suburb: " + item.Name + " | Cost: $" +item.Cost);
localStorage.setItem('alerted', item.Pincode);
}
}
});
};
xhr.open('GET', chrome.extension.getURL('data/tolllist.json'), true);
xhr.send();
},3000);