Skip to content

Instantly share code, notes, and snippets.

@phstc
Created December 22, 2010 14:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phstc/751586 to your computer and use it in GitHub Desktop.
Save phstc/751586 to your computer and use it in GitHub Desktop.
Use this Bookmarklet to start monitoring a page for changes. When a page change is detected you will receive an alert notifying the changes
javascript:(function(){
/*@author Pablo Cantero - http://pablocantero.com/blog/2010/09/15/javascript-para-notificar-se-o-site-teve-alteracoes*/
var xmlHttp = getXMLHttpObj();
if(xmlHttp == null){
alert('Failed to load XMLHTTP');
return;
}
var actual = getPageContent(xmlHttp, window.location.href);
var intervalId = window.setInterval(function(){
var current = getPageContent(xmlHttp, window.location.href);
if(actual != current){
alert('This page has been modified since you opened it');
window.clearInterval(intervalId);
}
}, 1000);
function getPageContent(xmlHttp, url){
xmlHttp.open('GET', window.location.href, false);
xmlHttp.send('');
return xmlHttp.responseText;
}
function getXMLHttpObj(){
if(typeof(XMLHttpRequest)!='undefined')
return new XMLHttpRequest();
var axO=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
for(var i = 0; i < axO.length; i++){
try{
return new ActiveXObject(axO[i]);
}catch(e){}
}
return null;
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment