Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Created June 26, 2017 17:08
Show Gist options
  • Save AlbinoDrought/ddc1f29ef6509971b316e4851c15aebf to your computer and use it in GitHub Desktop.
Save AlbinoDrought/ddc1f29ef6509971b316e4851c15aebf to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Automatic Tab Closer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description No more tab hogging ;)
// @author AlbinoDrought
// @match *://www.w3schools.com/*
// @match *://php.net/*
// @match *://www.google.ca/*
// @grant window.close
// ==/UserScript==
(function() {
'use strict';
var timeoutReference = false;
var delay = 10000;
function onTimeout() {
window.close();
}
function resetTimer() {
if (timeoutReference !== false) {
clearTimeout(timeoutReference);
}
timeoutReference = setTimeout(onTimeout, delay);
}
document.addEventListener("load", resetTimer);
document.addEventListener("mousemove", resetTimer);
document.addEventListener("keypress", resetTimer);
document.addEventListener("click", resetTimer);
document.addEventListener("scroll", resetTimer);
resetTimer();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment