gtgt / redalert

// ==UserScript==
// @name        redalert
// @namespace   redalert
// @include     https://redmine.aion.hu/issues*
// @match       https://redmine.aion.hu/issues*
// @version     1
// @grant       none
// ==/UserScript==

if (!$('#watcher').length) {
  $('<div id="watcher" style="position: fixed; z-index: 9999; background-color: white; padding: .5em; right: 0; bottom: 0;"><audio id="weewoo"><source src="http://soundbible.com/grab.php?id=1911&type=mp3" type="audio/mpeg"></source></audio>Szójjá!&nbsp;</div>').append($('<input type="checkbox" checked="checked" />').change(function() {
		var $this = $(this), color = $this.parent().css('color'), $weewoo = $('#weewoo');
    if (this.checked) {
      $this.data('tim', setInterval(function() {
        $.ajax({url: location.href, success: function(data) {
          if (data) {
            $('#content').html(data);
            if ($('tr.issue', '.list.issues').length) {
              $('#weewoo').get(0).play();
              $this.parent().animate({color: '#f00', fontSize: '+=10px'}, 500, function() {
                $this.parent().animate({color: color, fontSize: '-=10px'}, 500);
              });
            } else {
              $weewoo[0].pause();
            }
          }
        }});
      }, 5000));
    } else {
      clearInterval($this.data('tim'));
			$weewoo[0].pause();
      $weewoo[0].fastSeek(0);
    }
  })).appendTo('body').find(':checkbox').triggerHandler('change');
} else {
  alert('nah!');
}