Last active
May 9, 2018 16:27
-
-
Save glendonyeo/fa20f9a3217fc914b1d536573073bb9b to your computer and use it in GitHub Desktop.
PRU 14 Monitor Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; | |
po.src = 'https://code.jquery.com/jquery-1.12.4.min.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); | |
})(); | |
var ph = []; | |
var bn = []; | |
var pas = []; | |
var count = 0; | |
function getData(){ | |
var ph_new = []; | |
var bn_new = []; | |
var pas_new = []; | |
var ph_diff = [];var bn_diff = [];var pas_diff = []; | |
$.get( "http://ge14.undi.info.s3-website-ap-southeast-1.amazonaws.com/", function( data ) { | |
var newBody = $(data); | |
var state = newBody.find('.negeri'); | |
state.each(function(i,e){ | |
$(e).find('.parl').each(function(j,f){ | |
var current_ele = $(f).find('h2'); | |
if(current_ele.hasClass('party_bn')){ | |
bn_new.push($(f).find('h9').text()); | |
} | |
else if(current_ele.hasClass('party_ph')){ | |
ph_new.push($(f).find('h9').text()); | |
} | |
else if(current_ele.hasClass('party_pas')){ | |
pas_new.push($(f).find('h9').text()); | |
} | |
}); | |
}); | |
jQuery.grep(ph_new, function(el) { | |
if (jQuery.inArray(el, ph) == -1) ph_diff.push(el); | |
}); | |
jQuery.grep(bn_new, function(el) { | |
if (jQuery.inArray(el, bn) == -1) bn_diff.push(el); | |
}); | |
jQuery.grep(pas_new, function(el) { | |
if (jQuery.inArray(el, pas) == -1) pas_diff.push(el); | |
}); | |
jQuery.grep(ph, function(el) { | |
if (jQuery.inArray(el, ph_new) == -1) ph_diff.push(el + " (Removed)"); | |
}); | |
jQuery.grep(bn, function(el) { | |
if (jQuery.inArray(el, bn_new) == -1) bn_diff.push(el + " (Removed)"); | |
}); | |
jQuery.grep(pas, function(el) { | |
if (jQuery.inArray(el, pas_new) == -1) pas_diff.push(el + " (Removed)"); | |
}); | |
if(ph_diff.length || bn_diff.length || pas_diff.length){ | |
window.lala = data; | |
$('.body').html(jQuery(newBody).find('.body').html()); | |
console.log('BN => '+ newBody.find('.party_bn').find('h8').text()); | |
console.log('PH => '+ newBody.find('.party_ph').find('h8').text()); | |
console.log('PAS => '+ newBody.find('.party_pas').find('h8').text()); | |
console.log("PH New => " + ph_diff.join(",")); | |
console.log("BN New => " + bn_diff.join(",")); | |
console.log("PAS New => " + pas_diff.join(",")); | |
}else{ | |
console.log('refreshed'); | |
} | |
bn = bn_new; | |
pas = pas_new; | |
ph = ph_new; | |
}); | |
} | |
setInterval(getData,6000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment