Skip to content

Instantly share code, notes, and snippets.

@seb-thomas
Last active December 13, 2015 22:29
Show Gist options
  • Save seb-thomas/4984941 to your computer and use it in GitHub Desktop.
Save seb-thomas/4984941 to your computer and use it in GitHub Desktop.
Redmine issue updated?
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