-
-
Save tomviner/5091634 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
if(typeof jQuery !== 'undefined'){ | |
jQuery(function($) { | |
var dateUpdated = ""; | |
var reDate = /(\d+)\/(\d+)\/(\d+)/; | |
var reIssues = /issues\/\d+/; | |
var titleDate = $('p.author a').last().attr('title'); | |
var style= 'position: fixed;bottom: 0px;margin-bottom: 0px;width: 100%;padding: 12px 0px 13px 30px;background-position-y: 12px;'; | |
var warning = '<div class="flash warning" style="'+style+'">This issue has been updated since you last saw it. <a href="javascript:location.reload(true);">Refresh now</a></div>'; | |
var currentURL = window.location.pathname; | |
var favi = $('[rel="shortcut icon"]'); | |
//Swap year and day, convert to Date obj | |
if (titleDate) { | |
titleDate = (titleDate).replace(reDate, "$3/$2/$1"); | |
titleDate = new Date(titleDate); | |
} | |
function changeTitle() { | |
$.get( | |
location.pathname + '.json', | |
function(data){ | |
dateUpdated = data.issue.updated_on; | |
dateUpdated = new Date(dateUpdated); | |
dateUpdated.setSeconds(0); | |
if (dateUpdated.getTime() > titleDate.getTime()) { | |
//If theres a time diff, change the favicon | |
favi.attr('href', 'http://i.imgur.com/Y4xLgSt.png'); | |
$('#wrapper').append(warning); | |
}else{ | |
//If not, keep checking, dammit! | |
/* | |
console.group("Updated?"); | |
console.log(dateUpdated.getTime(), dateUpdated, ' Time stamp on server'); | |
console.log(titleDate.getTime(), titleDate); | |
console.log('CHECKING BZZZKP--d[ o_o ]b'); | |
console.groupEnd(); | |
*/ | |
setTimeout(changeTitle, 10000); | |
} | |
} | |
); | |
} | |
if (currentURL.match(reIssues)) changeTitle(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment