-
Notifications
You must be signed in to change notification settings - Fork 1
/
stockupdate.js
55 lines (51 loc) · 1.8 KB
/
stockupdate.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
// function puts in the passed argument text into div#stocks
function putInStocksDiv(text) {
document.querySelector('#stocks').innerHTML = text;
}
// makes an asynchronous XMLHttpRequest to external url and puts the response text into div#stocks
var loadStocksInit = function(uri) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
putInStocksDiv(this.responseText);
this.abort();
}
};
xhttp.open("GET", uri, true);
xhttp.send();
}
var populateStocksInit = function() {
loadStocksInit("stocktable.php");
};
var populateNews = function() {
loadStocksInit("newstable.php");
};
var loadStocksLater = function(uri) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var ds = document.querySelector('div#stocks');
var dh = document.querySelector('div#hidden');
dh.innerHTML = ds.innerHTML;
ds.innerHTML = this.responseText;
ds.id = "shown";
var dstrs = document.querySelectorAll("div#shown table tr");
var dhtrs = document.querySelectorAll("div#hidden table tr");
if(dstrs.length == dhtrs.length) {
for(var i = 0; i < dstrs.length; i++) {
if(dstrs[i].innerHTML !== dhtrs[i].innerHTML) {
dstrs[i].style.backgroundColor = 'yellow';
dstrs[i].style.color = '#000';
}
}
}
ds.id = "stocks";
this.abort();
}
};
xhttp.open("GET", uri, true);
xhttp.send();
};
var populateStocksLater = function() {
loadStocksLater('stocktable.php');
};