Skip to content

Instantly share code, notes, and snippets.

@Stvad
Last active October 2, 2017 18:05
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 Stvad/8400cf8ce2cd2c6a19b9d9579faad061 to your computer and use it in GitHub Desktop.
Save Stvad/8400cf8ce2cd2c6a19b9d9579faad061 to your computer and use it in GitHub Desktop.
Greasmonkey script to ask you if you really want to access some distracting web resource
// ==UserScript==
// @name Timeout blocker v2
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @match https://www.facebook.com/*
// ==/UserScript==
//--- The @grant directive is used to restore the proper sandbox.
let storageKey = window.location.origin +'LoadTime';
let interval = 600000;
let pastThreshold = Number(new Date()) - interval;
function displayOverlay() {
let unlockPhrase = 'I do want to open this resource';
let questionInput = $('<input>', {id: 'question_input'});
let overlay = $('<div>', {class: 'overlay'}).append($('<div>', {class: 'question_block'}).append(
$('<label>', {for: 'question_input', text: `Are you really sure you want to do this? If yes - please type the unlock phrase in.`}),
questionInput));
$('body').append(overlay);
overlay.keypress((event) => {
if (event.which == 13 && questionInput.val() === unlockPhrase) {
overlay.hide();
}
});
}
let lastLoaded = GM_getValue(storageKey, pastThreshold);
if (lastLoaded <= Number(new Date()) - interval) {
displayOverlay();
GM_setValue(storageKey, Number(new Date()));
}
GM_addStyle(`
.overlay {
position: fixed; /* Sit on top of the page content */
display: block; /* Hidden by default */
width: 100%; /* Full width (cover the whole page) */
height: 100%; /* Full height (cover the whole page) */
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.99); /* Black background with opacity */
z-index: 2; /* Specify a stack order in case you're using a different order for other elements */
cursor: pointer; /* Add a pointer on hover */
}
.question_block {
width: 80em;
height: 3em;
position: fixed;
top: 50%;
left: 40%;
display: block;
}
#question_input {
margin-left: 20px;
width: 25em;
height: 2em;
}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment