Skip to content

Instantly share code, notes, and snippets.

@jsmrcaga
Created August 18, 2016 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmrcaga/e1289a0980c4c732d6a78c2faed2755e to your computer and use it in GitHub Desktop.
Save jsmrcaga/e1289a0980c4c732d6a78c2faed2755e to your computer and use it in GitHub Desktop.
a small script to get the time needed to close a tab
// 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