// Webolodeon
// version 2.3
// 2005-05-23
// Copyright (c) 2005, Danny O'Brien
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// ==UserScript==
// @name          Webolodeon
// @namespace     http://www.oblomovka.com/code/webolodeon
// @description   Restrict your browsing to five minute bursts.
// ==/UserScript==

(function() {
var TimeKeeper = {
MAX_SURF_TIME : 5 * 60 * 1000,
TIME_BEFORE_RESET : 3 * 60 * 1000,

resetTimer: function () {
var now = (new Date()).getTime();
GM_setValue("surfBegan", now.toString());
GM_setValue("lastPage", now.toString());
// GM_log(new Date() + "** RESET:" + now.toString());
},

// Now, the routine that tells us whether its legit to display a page or not
isWithinTimeLimit: function () {
    var now = (new Date()).getTime()
    var begin_time = Number(GM_getValue("surfBegan"));
    var last_time = Number(GM_getValue("lastPage"));
//    GM_log(new Date() + "** CHECKTIME: " + (last_time - begin_time));

    // Is it over TIME_BEFORE_RESET since we last loaded a page?
    // If so, reset counters.
    if ((last_time + this.TIME_BEFORE_RESET ) < now)
        {
        this.resetTimer();
        return 1; 
        }
    GM_setValue("lastPage", now.toString());
    
    // Otherwise, have we been surfing too long?
    if ((begin_time + TimeKeeper.MAX_SURF_TIME ) > now)
        { 
        return 1; } 
    return 0;
}
}

var Warning = {
display: function() {
    var harangue = "You've been surfing for too long!\n You must put another nickel in!";
    var satisfactory = 0;
    while (!satisfactory) {
    var excuse = window.prompt(harangue,"your excuse");
    if (excuse.length < 20) {
        harangue = "Too short an excuse. Try again.";
        continue;
        }
    satisfactory = 1;
    }
    TimeKeeper.resetTimer();
}
}

if (TimeKeeper.isWithinTimeLimit()) 
    { 
    return;
    }
Warning.display();
})()
