Created
October 5, 2008 08:39
-
-
Save masuidrive/14863 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
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