Created
August 18, 2016 10:18
-
-
Save jsmrcaga/e1289a0980c4c732d6a78c2faed2755e to your computer and use it in GitHub Desktop.
a small script to get the time needed to close a tab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Closing time with mouse, trackpad and keyboard | |
;(function(){ | |
var begin = null; | |
var mouseMoved = false; | |
window.times = { | |
mouse: [], | |
keyboard: [], | |
trackpad: [], | |
}; | |
Object.defineProperty(window.times, 'getAverages', { | |
enumerable: false, | |
value: function(){ | |
console.info('Average for mouse:', times.mouse.reduce((p, c) => p+c) / times.mouse.length); | |
console.info('Average for trackpad:', times.trackpad.reduce((p, c) => p+c) / times.trackpad.length); | |
console.info('Average for keyboard:', times.keyboard.reduce((p, c) => p+c) / times.keyboard.length); | |
} | |
}); | |
var currentTimes = times.mouse; | |
// reset variables | |
// and prevent window from closing | |
window.onbeforeunload = function(){ | |
var time = Date.now() - begin; | |
currentTimes.push(time); | |
console.info('Time', time, 'ms'); | |
mouseMoved = false; | |
return 'plep'; | |
}; | |
window.onmousemove = function(){ | |
if(mouseMoved){ | |
return; | |
} | |
begin = Date.now(); | |
mouseMoved = true; | |
}; | |
window.setClosingMethod = function(method){ | |
currentTimes = times[method]; | |
}; | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment