-:TA Alert Status:-

Alert if someone attacks your bases.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        -:TA Alert Status:-
// @description Alert if someone attacks your bases.
// @namespace   http*://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include     https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @icon        http://c2n.me/ivdCY1.png
// @version     1.0.1
// @author      der_flake
// ==/UserScript==

(function () {
    var original_title = window.document.title;
    var enable_sound   = true; // false
    var was_attacked   = false;
    
if(enable_sound) {
    siren = new Audio('http://booz.ro/tiberium/siren.mp3'); 
    siren.addEventListener('ended', function() {
        this.currentTime = 0;
        this.play();
    }, false);
}
    
    function checkAlert() {
        var in_background = false;
        var new_title     = "";
        var is_alerted    = false;
            
        if (document.hasFocus() == false) {
            in_background = true;
        }
        
        if(in_background) {
            var mainData  = ClientLib.Data.MainData.GetInstance();
            var bases     = mainData.get_Cities();
            var all_bases = bases.get_AllCities().d;
            var victim    = "";

            for (var key in all_bases) {
               var current_base = all_bases[key];
                if(current_base.get_isAlerted()) {
                    is_alerted = true;
                    victim = current_base.get_Name();
                    was_attacked = true;
                }
            }
        }

        if(is_alerted && !was_attacked) {
            window.document.title = 'ALERT - База ' + victim + ' под атакой!';
            makeFavicon("alert");
            
            if(enable_sound) {
                siren.play();
            }
        } else if(was_attacked && !in_background) {
            window.document.title = original_title;
            makeFavicon("relax");
            
            if(enable_sound) {
                siren.pause();
                siren.currentTime = 0;
            }

            was_attacked = false;
        }
    }
    
    function makeFavicon(status) {
        var link = document.createElement('link'),
            new_href = "";
        
        if(status == "alert") {
            new_href = "http://c2n.me/iv7pNm.gif";
        } else if(status == "relax") {
            new_href = "http://c2n.me/iv8Y2f.png";
        }

        link.rel  = 'shortcut icon';
        link.href = new_href;
        
        document.getElementsByTagName('head')[0].appendChild(link);
    }
    
    window.setInterval(function(){
        checkAlert();
    }, 5000);
    
    console.log("-:TA Alert Status:- loaded!");

})();