galkowski.tgmail.com / cantrhound

// ==UserScript==
// @name        cantrhound
// @description tracker for new events for your characters in Cantr II game
// @author      2015, Tomasz GaƂkowski
// @namespace   https://cantr.net/
// @include     https://cantr.net/*
// @version     1.0.3
// ==/UserScript==
// ==OpenUserJS==
// @author		galkowski.tgmail.com
// ==/OpenUserJS==

var title = document.cookie.replace(/(?:(?:^|.*;\s*)title\s*\=\s*([^;]*).*$)|^.*$/, "$1");
document.title = title;

// I found no better way to check if this is a character screen that would work on all languages
if (document.body.innerHTML.search("Multiplayer Online Games Directory") !== -1) {
    setInterval(refresh, 20000);
}

function refresh() {
    var counter = 0;
    var activeCharacters = [];
    var newEvents = false;

    for (var i = 1; i < 15; i++) {
        var character = document.querySelectorAll("label[for=char_" + i +"]");
        if (character[0] !== undefined) {
            var color = character[0].children[0].style.color;
        
            if (color !== "rgb(119, 119, 119)") {
                activeCharacters.push(character);
            }
        }
    }

    counter = activeCharacters.length;

    if (counter !== document.cookie.replace(/(?:(?:^|.*;\s*)counter\s*\=\s*([^;]*).*$)|^.*$/, "$1")) {
        newEvents = true;
    }

    document.title = "(" + counter + ") Cantr II"
    titleCookie = "title=" + document.title;
    document.cookie = titleCookie;
    document.cookie = "counter=" + counter;

    window.location.reload();
}