trabladorr / Minethings Title Notifications

// ==UserScript==
// @name         Minethings Title Notifications
// @version      0.1.6
// @description  Append ">>" or "(#)" to page title, if a mine has new findings, or if # messages have arrived.
// @author       trabladorr
// @downloadURL  https://openuserjs.org/src/scripts/trabladorr/Minethings_Title_Notifications.min.user.js
// @updateURL    https://openuserjs.org/meta/trabladorr/Minethings_Title_Notifications.meta.js

// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @grant        none
// @match        http://*.minethings.com/*
// ==/UserScript==

var $j = jQuery.noConflict();


var checker = function(){
  //remove previous modifications from the title
  var title = document.title.replace(/([>]|\(\d*\))/g, '');

  //append number of messages to new title, if any have arrived
  var MessagesLink = $j("#MessagesDiv");
  if (MessagesLink.text().includes("("))
    title = MessagesLink.text().substring(MessagesLink.text().indexOf("("))+title;
    
  //append ">>" to new title, if new findings available
  var MinesLink = $j("#FindingsDiv");
  if (MinesLink.text().includes(">>"))
    title = ">>"+title;

  //set the new title
  document.title = title;
  
  //repeat every second
  setTimeout(checker,1000);
};

checker();//start script