Created
November 5, 2019 13:39
-
-
Save sarfraznawaz2005/c8032ca860f8cc6b31b4b7c0b309ca9e to your computer and use it in GitHub Desktop.
userscript to lock a website by password
This file contains hidden or 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
// ==UserScript== | |
// @name Lock Screen | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Locks given websites. | |
// @author Sarfraz | |
// @match https://web.whatsapp.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var pin = "sarfraz786"; | |
var timeoutMinutes = 3; | |
var idleTimer = null; | |
hide(); | |
setupInterval(); | |
$('*').bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick', function () { | |
clearInterval(idleTimer); | |
setupInterval(); | |
}); | |
function setupInterval() { | |
idleTimer = setInterval(hide, timeoutMinutes * 60000); | |
} | |
function hide() { | |
var pinDiv = document.createElement("div"); | |
pinDiv.style = "position: fixed; z-index: 9999; top: 0px; left: 0px; width: 100%; height: 100%; background-color: #fff"; | |
pinDiv.innerHTML = ``; | |
document.body.appendChild(pinDiv); | |
var pinInput = document.createElement("input"); | |
pinInput.type = "password"; | |
//pinInput.autofocus = true; | |
pinInput.style = "position: absolute; top: 5px; right: 5px; width: 100px; height: 30px; margin-top: -15px; font-size: 20px; border:none; color: transparent; text-shadow: 0 0 0 red; "; | |
pinDiv.appendChild(pinInput); | |
pinInput.oninput = function () { | |
if (pinInput.value === pin) { | |
document.body.removeChild(pinDiv); | |
} | |
}; | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While above is based on password, this is based on long click: