Last active
May 29, 2022 11:31
-
-
Save lelinhtinh/519be990ba6a092265d06cc95935bb56 to your computer and use it in GitHub Desktop.
F12 > Console (Firefox: Ctrl+Shift+K, Chrome: Ctrl+Shift+J)
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
(function() { | |
var setResult = [11, 22, 33, 44, 55, 69], | |
total = setResult.length, | |
count = 0, | |
iframe = document.getElementById('homepage-generator').getElementsByTagName('IFRAME')[0], | |
iframeDocument = iframe.contentDocument || iframe.contentWindow.document, | |
generator = iframeDocument.getElementById('true-random-integer-generator-button'), | |
result = iframeDocument.getElementById('true-random-integer-generator-result'), | |
min, | |
max, | |
loadEffect, | |
randomNumber = function(x, y) { | |
return Math.floor((Math.random() * (y + 1 - x)) + x); | |
}; | |
generator.removeAttribute('onclick'); | |
generator.onclick = function() { | |
min = parseInt(iframeDocument.getElementById('true-random-integer-generator-min').value, 10); | |
max = parseInt(iframeDocument.getElementById('true-random-integer-generator-max').value, 10); | |
if (min >= max) { | |
max = ++min; | |
iframeDocument.getElementById('true-random-integer-generator-max').value = max; | |
result.innerHTML = randomNumber(min, max); | |
return; | |
} | |
result.innerHTML = '<img src="/util/cp/images/ajax-loader.gif" alt="Loading..." />'; | |
clearTimeout(loadEffect); | |
loadEffect = setTimeout(function() { | |
result.innerHTML = (count < total) ? setResult[count] : randomNumber(min, max); | |
count++; | |
}, ((Math.floor(Math.random() * 5) + 3) * 100)); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bookmarklet version
https://jsfiddle.net/baivong/rhecyrm4/show/