Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <script>
- //Author: Jordan Stefanelli
- //GPL License: Just kidding. I don't care, this code is awful.
- // Some global vars that the functions reference.
- var g_content = ''; // content = array of split up words from the text area
- var g_idx = 0; // the current word to display (the #'d position of the word)
- var g_interval = 400; // How many milliseconds to update the word display
- var g_running = false; // Track if the application is running
- var g_timer = null; // Storage variable for the looping call to update & display words.
- // Gate-keeper to only allow starting if we're not running.
- // Called when clicking "start"
- function start_words()
- {
- if (!g_running)
- {
- g_running = true;
- g_timer = setInterval(flash_words, g_interval);
- }
- }
- // Stop the looping call, reset the paragraph position to 0, signal that we are not running.
- // Called when clicking 'stop'
- function stop_words()
- {
- if (g_running)
- {
- g_running = false;
- g_idx = 0;
- clearInterval(g_timer);
- }
- }
- // This is called if you
- function set_reading_interval()
- {
- g_interval = document.getElementsByName('display_interval')[0].value;
- update_reading_interval();
- }
- // Called when clicking away from updating the reading interval box
- function update_reading_interval()
- {
- if (g_running)
- {
- clearInterval(g_timer);
- g_running = false;
- start_words();
- }
- }
- // This is called after you click away from the text box containing your reading content.
- function getContent()
- {
- text = document.getElementsByName('content')[0].value;
- g_content = text.split(' ');
- }
- // This method is internally called to update the word display.
- function flash_words()
- {
- word = g_content[g_idx];
- document.getElementsByName('display_field')[0].value = word;
- g_idx = ( g_idx + 1 ) % g_content.length;
- }
- </script>
- <body>
- <textarea name="display_interval" onBlur="set_reading_interval();">400</textarea>
- <textarea name="content" style="width:400px;height:400px;" onBlur="getContent();"></textarea>
- <br>
- <textarea style="font-size:200px;font-family:courier new;" name="display_field">test</textarea>
- <br>
- <input type="button" value="Go." onClick="start_words();flash_words();"></input>
- <input type="button" value="Stop." onClick="stop_words();"></input>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement