From c9ae718b8e96ba5a6a175cd4549bd602fc363eee Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 14 Jul 2011 12:55:36 +0200 Subject: [PATCH] add testing timer for flexibility with allowed duration and thresholds --- greasemonkey/virtualblinders.user.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/greasemonkey/virtualblinders.user.js b/greasemonkey/virtualblinders.user.js index e1abbda..f52a1a5 100644 --- a/greasemonkey/virtualblinders.user.js +++ b/greasemonkey/virtualblinders.user.js @@ -11,18 +11,32 @@ ## consider include * then refine pattern per task # make timers (default to 0 sec, value defined via the script or a GM_Value) to be more flexible ## reset timer either manually or per day (i.e.) reset if last set date <5AM +## set 2 thresholds, the first as a warning, the second as an action -See setTimeout() to make a counter. +Note that it does work even when Flash has focus. */ +var t; +var MODE="video"; +var time_spent = GM_getValue(MODE,0); + GM_xmlhttpRequest({ method: "GET", url: "http://fabien.benetou.fr/pub/currenttask", onload: function(response) { task = response.responseText; if (task == 'Reading\n' || task == 'Programming\n'){ - document.body.innerHTML="You should be focusing on "+task+" instead,\nare you sure you need that information from that website?"; + //document.body.innerHTML="You should be focusing on "+task+" instead,\nare you sure you need that information from that website?"; + document.body.innerHTML="You should be focusing on "+task+" instead,\nare you sure you need that information from that website?
Note that you have already spent "+time_spent+" seconds on that website so far!
"+document.body.innerHTML; + t=setInterval(mytimer,1000); + //see http://commons.oreilly.com/wiki/index.php/Greasemonkey_Hacks/Getting_Started#Pitfall_.231:_Auto-eval_Strings } } }); + +function mytimer(){ + time_spent=time_spent+1; + document.getElementById('timespent').innerText=time_spent; + GM_setValue(MODE,time_spent); +}