Last active
November 4, 2016 12:38
-
-
Save lexoyo/58925d3a158c59003399af2d7bac4d77 to your computer and use it in GitHub Desktop.
make the browser struggle
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 struggle.js | |
// @namespace lexoyo | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function sleep(milliseconds) { | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++) { | |
if ((new Date().getTime() - start) > milliseconds) { | |
break; | |
} | |
} | |
} | |
var start = Date.now(); | |
var duration = 30000; | |
var end = start + duration; | |
function rame() { | |
date = Date.now(); | |
sleep(1000); | |
date = Date.now(); | |
if(date < end) { | |
timerUI.innerHTML = Math.round((end - date)/1000); | |
window.requestAnimationFrame(rame); | |
} | |
else { | |
console.warn('RAME STOP'); | |
document.body.removeChild(timerUI); | |
} | |
} | |
var date = Date.now(); | |
console.info('RAME START', Math.round((Date.now() - date)/10)/100, 's'); | |
window.requestAnimationFrame(rame); | |
var timerUI = document.createElement('p'); | |
document.body.appendChild(timerUI); | |
timerUI.style.position = "fixed"; | |
timerUI.style.zIndex = "9999"; | |
timerUI.style.backgroundColor = "red"; | |
timerUI.style.padding = "10px"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment