Stackoverflow Response: Display a warning after 3 mins of inactivity on a page

http://stackoverflow.com/questions/16151112/display-a-warning-after-3-mins-of-inactivity-on-a-page/16151509#16151509

HTML

<a href="http://stackoverflow.com/questions/16151112/display-a-warning-after-3-mins-of-inactivity-on-a-page/16151509#16151509" target="_blank">http://stackoverflow.com/questions/16151112/display-a-warning-after-3-mins-of-inactivity-on-a-page/16151509#16151509</a>

JavaScript

var $area = $(document),
        idleActions = [
            {
                milliseconds: 3000, // 3 seconds
                action: function () { alert('Warning 2'); }
            },
            {
                milliseconds: 3000, // 3 + 3 = 6 seconds
                action: function () { alert('Logout'); }
            }
        ];


    function Eureka (event, times, undefined) {
        var idleTimer = $area.data('idleTimer');
        if (times === undefined) times = 0;
        if (idleTimer) {
            clearTimeout($area.data('idleTimer'));
        }
        if (times < idleActions.length) {
            $area.data('idleTimer', setTimeout(function () {
                idleActions[times].action(); // run the first action
                Eureka(null, ++times); // setup the next action
            }, idleActions[times].milliseconds));
        } else {
            // final action reached, prevent further resetting
            $area.off('mousemove click', Eureka);
        }
    };

    $area
        .data('idle', null)
        .on('mousemove click', Eureka);

Eureka();