Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created September 12, 2015 13:38
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 theapache64/1745fabda7744c2350c8 to your computer and use it in GitHub Desktop.
Save theapache64/1745fabda7744c2350c8 to your computer and use it in GitHub Desktop.
The below jQuery script will alert if the viewCount of a stackoverflow question changed.
$(document).ready(function(){
var prevViewCount = 0;
var isFirst = 1;
var url = window.location.href;
if(url.indexOf("/questions/") > -1){
console.log("Question found");
setInterval(function(){
$.get(url,function(data,status){
var myRegexp = /([\d]+)\stime[s]?/g;
var match = myRegexp.exec(data);
var viewCount = match[1];
if(prevViewCount!=viewCount){
if(prevViewCount!=0){
alert(viewCount +" view(s)"); // abc
}
prevViewCount = viewCount;
}else{
console.log("---------\nOld view count : "+prevViewCount);
console.log("New view count : "+viewCount+"\n---------")
}
});
},1000);
}else{
console.log("Not a question");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment