Created
April 9, 2020 11:36
-
-
Save paulera/5a03be4168347efa6a86405ef502bacf to your computer and use it in GitHub Desktop.
Site blocker for working focused
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
| blacklisted = [ | |
| 'facebook.com', | |
| 'www.facebook.com' | |
| ]; | |
| if (blacklisted.includes(window.location.hostname)) { | |
| now = new Date(); | |
| strNow = now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') | |
| workTime = [ '09:00', '18:00' ] | |
| if (strNow >= workTime[0] && strNow <= workTime[1]) { | |
| htmlNodes = document.getElementsByTagName('html'); | |
| for (var i = 0; i < htmlNodes.length; i++) { | |
| htmlNodes[i].remove(); | |
| } | |
| htmlNode = document.createElement('html'); | |
| htmlNode.innerHTML = "<head>" + | |
| "<meta http-equiv='Content-Security-Policy' content='default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;'>" + | |
| "<title>Stop slacking</title>" + | |
| "<style>" + | |
| "body { background-color: #fff59d; color: #f4511e; font-size: 40px; text-align:center;}" + | |
| "p { margin-top: 100px; margin-bottom: 25px; font-family:Arial; }" + | |
| "</style>" + | |
| "</head>" + | |
| "<body><p>Stop slacking and get back to work,<br/>you lazy fuck!</p><div id='image'></div></body>"; | |
| document.append(htmlNode); | |
| fetch('https://api.tenor.com/v1/random?q=lazy&limit=1') | |
| .then(res => res.json()) | |
| .then((out) => { | |
| imgurl = out.results[0].media[0].tinygif.url; | |
| console.log(imgurl); | |
| document.getElementById('image').innerHTML += "<img src='" + imgurl + "' />"; | |
| }).catch(err => console.error(err)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment