Skip to content

Instantly share code, notes, and snippets.

@masuidrive
Created October 5, 2008 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masuidrive/14863 to your computer and use it in GitHub Desktop.
Save masuidrive/14863 to your computer and use it in GitHub Desktop.
/*
http://la.ma.la/blog/diary_200601201204.htm
*/
if(location.search=="?autoreload") {
var __autoreload_last_contents = new Array();
setInterval(function(){
var check = function(path) {
var onload = function() {
(__autoreload_last_contents[path] && req.responseText != __autoreload_last_contents[path]) && location.reload(true);
__autoreload_last_contents[path] = req.responseText;
}
var req;
if (window.XMLHttpRequest){
req = new XMLHttpRequest();
req.onload = onload;
}
else {
req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = function() {
if (req.readyState == 4) onload();
}
}
req.open("GET", path+"?"+(new Date()).getTime(), true);
req.send(null);
}
check(location.href);
links = document.getElementsByTagName("link")
for (i = 0; i < links.length; i++) {
if(links[i].rel=="stylesheet") {
check(links[i].href);
}
}
},1*1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment