fixed incorrect event names (on required only using expand properties\!)

master
Fabien Benetou 14 years ago
parent 12d9339ded
commit 205ca9cd6b
  1. 17
      greasemonkey/virtualblinders.user.js

@ -9,7 +9,7 @@
# handle background tab # handle background tab
## stop timer when focus lost window.onunload or window.onblur ## stop timer when focus lost window.onunload or window.onblur
## restart timer when focus is back window.load or window.onfocus ## restart timer when focus is back window.load or window.onfocus
## XXX failing so far ## XXX what is happening when 2 background tabs are increasing the timer?!
# improve the list of websites to include # improve the list of websites to include
## consider include * then refine window.location pattern per task ## consider include * then refine window.location pattern per task
# make timers (default to 0 sec, value defined via the script or a GM_Value) to be more flexible # make timers (default to 0 sec, value defined via the script or a GM_Value) to be more flexible
@ -34,10 +34,10 @@ GM_xmlhttpRequest({
}); });
function responseCheck(task) { function responseCheck(task) {
//task = 'Reading\n'; task = 'Reading\n';
timeThreshold = 600; timeThreshold = 600;
aboveThreshold = ( timeThreshold < time_spent ); aboveThreshold = ( timeThreshold < time_spent );
//aboveThreshold = true; aboveThreshold = false;
if (task == 'Reading\n' || task == 'Programming\n'){ if (task == 'Reading\n' || task == 'Programming\n'){
if ( !aboveThreshold ) { if ( !aboveThreshold ) {
//under threshold, just display a warning and the content //under threshold, just display a warning and the content
@ -52,9 +52,9 @@ function responseCheck(task) {
//regarding the specific syntax //regarding the specific syntax
//see http://commons.oreilly.com/wiki/index.php/Greasemonkey_Hacks/Getting_Started#Pitfall_.231:_Auto-eval_Strings //see http://commons.oreilly.com/wiki/index.php/Greasemonkey_Hacks/Getting_Started#Pitfall_.231:_Auto-eval_Strings
GM_log("register listeners"); GM_log("register listeners");
window.addEventListener("onblur", stopTimer, true); window.addEventListener("blur", stopTimer, true);
window.addEventListener("onfocus", restartTimer, true); window.addEventListener("focus", restartTimer, true);
window.addEventListener("onunload", setTotalTimeSpent, true); window.addEventListener("unload", setTotalTimeSpent, true);
} else { } else {
//above threshold, only display the warning without the content //above threshold, only display the warning without the content
document.body.innerHTML="You should be focusing on <a href=\"http://fabien.benetou.fr/CognitiveEnvironments/" document.body.innerHTML="You should be focusing on <a href=\"http://fabien.benetou.fr/CognitiveEnvironments/"
@ -71,15 +71,11 @@ function mytimer() {
//GM_log("timer tick"); //GM_log("timer tick");
time_spent=time_spent+1; time_spent=time_spent+1;
//fail document.getElementById('timespent').innerText=time_spent; //fail document.getElementById('timespent').innerText=time_spent;
GM_setValue(MODE,time_spent);
// this should only be un setTotalTimeSpent() but since the events do not work this will remain here for now
} }
function stopTimer() { function stopTimer() {
GM_log("stop timer"); GM_log("stop timer");
// never called!
window.clearInterval(t); window.clearInterval(t);
// tested and worked, t value is correct
} }
function restartTimer() { function restartTimer() {
@ -90,4 +86,5 @@ function restartTimer() {
function setTotalTimeSpent() { function setTotalTimeSpent() {
GM_log("set total time spent"); GM_log("set total time spent");
GM_setValue(MODE,time_spent); GM_setValue(MODE,time_spent);
// probably better to re-read the value then add the time ellapsed since
} }

Loading…
Cancel
Save