Created
September 12, 2015 13:38
-
-
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.
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
$(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