Last active
November 8, 2018 00:29
-
-
Save Shilo/e0f65c6be0aff74c51c0 to your computer and use it in GitHub Desktop.
[This script no longer works, because the game is rendered via canvas tag.] Auto type javascript injection for www.nitrotype.com. (Warning: Too high of WPM will be detected by the anti-cheat engine)
This file contains 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 ($, window) { | |
var intervals = {}; | |
var removeListener = function(selector) { | |
if (intervals[selector]) { | |
window.clearInterval(intervals[selector]); | |
intervals[selector] = null; | |
} | |
}; | |
var found = 'waitUntilExists.found'; | |
/** | |
* @function | |
* @property {object} jQuery plugin which runs handler function once specified | |
* element is inserted into the DOM | |
* @param {function|string} handler | |
* A function to execute at the time when the element is inserted or | |
* string "remove" to remove the listener from the given selector | |
* @param {bool} shouldRunHandlerOnce | |
* Optional: if true, handler is unbound after its first invocation | |
* @example jQuery(selector).waitUntilExists(function); | |
*/ | |
$.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) { | |
var selector = this.selector; | |
var $this = $(selector); | |
var $elements = $this.not(function() { return $(this).data(found); }); | |
if (handler === 'remove') { | |
// Hijack and remove interval immediately if the code requests | |
removeListener(selector); | |
} | |
else { | |
// Run the handler on all found elements and mark as found | |
$elements.each(handler).data(found, true); | |
if (shouldRunHandlerOnce && $this.length) { | |
// Element was found, implying the handler already ran for all | |
// matched elements | |
removeListener(selector); | |
} | |
else if (!isChild) { | |
// If this is a recurring search or if the target has not yet been | |
// found, create an interval to continue searching for the target | |
intervals[selector] = window.setInterval(function () { | |
$this.waitUntilExists(handler, shouldRunHandlerOnce, true); | |
}, 500); | |
} | |
} | |
return $this; | |
}; | |
}(jQuery, window)); | |
//================================================================= | |
$('.newRace').waitUntilExists(function () { | |
simulateKeyPressCharCode(13); | |
}); | |
var desiredWordsPerMinute = 100; | |
var errorsPerMinute = 100; | |
var errorChar = "~"; | |
//don't change below | |
var MS_PER_MIN = 60000; | |
var averageLettersPerWord = 5; | |
var lettersPerMinute = desiredWordsPerMinute * averageLettersPerWord; | |
var letterDelay = lettersPerMinute>0 ? MS_PER_MIN/lettersPerMinute : 0; | |
var errorDelay = errorsPerMinute>0 ? MS_PER_MIN/errorsPerMinute : 0; | |
function simulateKeyPress(character) { | |
jQuery.event.trigger({ type : 'keypress', which : character.charCodeAt(0) }); | |
} | |
function simulateKeyPressCharCode(charCode) { | |
jQuery.event.trigger({ type : 'keypress', which : charCode }); | |
} | |
if (errorDelay > 0) | |
setInterval(function(){ simulateKeyPress(errorChar) }, errorDelay); | |
var i = 1; | |
jQuery('#lessonContent').children('div').each(function () { | |
var char = jQuery(this).text(); | |
if (char && char.length > 0) | |
{ | |
if (letterDelay > 0) | |
setTimeout(function(){ simulateKeyPress(char); }, letterDelay * i); | |
else | |
simulateKeyPress(char); | |
i++; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/prail/11d7e0603a8a54af2e83f286502cd6cc My bot that works with the canvas version.