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
## stop timer when focus lost window.onunload or window.onblur
## 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
## 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
@ -34,10 +34,10 @@ GM_xmlhttpRequest({
});
function responseCheck(task) {
//task = 'Reading\n';
task = 'Reading\n';
timeThreshold = 600;
aboveThreshold = ( timeThreshold < time_spent );
//aboveThreshold = true;
aboveThreshold = false;
if (task == 'Reading\n' || task == 'Programming\n'){
if ( !aboveThreshold ) {
//under threshold, just display a warning and the content
@ -52,9 +52,9 @@ function responseCheck(task) {
//regarding the specific syntax
//see http://commons.oreilly.com/wiki/index.php/Greasemonkey_Hacks/Getting_Started#Pitfall_.231:_Auto-eval_Strings
GM_log("register listeners");
window.addEventListener("onblur", stopTimer, true);
window.addEventListener("onfocus", restartTimer, true);
window.addEventListener("onunload", setTotalTimeSpent, true);
window.addEventListener("blur", stopTimer, true);
window.addEventListener("focus", restartTimer, true);
window.addEventListener("unload", setTotalTimeSpent, true);
} else {
//above threshold, only display the warning without the content
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");
time_spent=time_spent+1;
//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() {
GM_log("stop timer");
// never called!
window.clearInterval(t);
// tested and worked, t value is correct
}
function restartTimer() {
@ -90,4 +86,5 @@ function restartTimer() {
function setTotalTimeSpent() {
GM_log("set total time spent");
GM_setValue(MODE,time_spent);
// probably better to re-read the value then add the time ellapsed since
}

Loading…
Cancel
Save