Add Mailcount for "All Mails"

try to take over the world...and add the mail count to the title

As of 2017-10-18. See the latest version.

// ==UserScript==
// @name         Add Mailcount for "All Mails"
// @namespace    http://tampermonkey.net/
// @version      0.11
// @description  try to take over the world...and add the mail count to the title
// @author       Csabinho
// @include      https://mail.google.com/*
// @grant        none
// ==/UserScript==

function addMailCountToTitle() {
    var mailCountIterator/* = document.evaluate('//*[@id=":wy"]/span/span[2]', document.body, null, XPathResult.ANY_TYPE, null)*/;
    var mailCount/* = mailCountIterator.iterateNext()*/;
    var debug = false;

    if((document.title).includes("@gmail.com") || ((document.title).match(/Gmail\(.*\)/)) !== null)
    {
        do
        {
            mailCountIterator = document.evaluate('//*[@id=":wy"]/span/span[2]', document.body, null, XPathResult.ANY_TYPE, null);
            mailCount = mailCountIterator.iterateNext();
            if(debug)console.log(document.title);
            if(mailCount)
            {
                document.title = "Gmail ("+mailCount.innerHTML+")";
                if(debug)console.log(mailCount.innerHTML);
            }
            else
            {
                if(debug)console.log("null, ffs");
            }
        }while(mailCount === null);

        return mailCount !== null;
    }
    else
    {
        if(debug)console.log("wrong title, ffs");
        return false;
    }
}

if((window.location.href) == "https://mail.google.com/mail/u/0/#all") //Workaround for not @include
{
    var t=setInterval(addMailCountToTitle,1000);
}