Advertisement
Guest User

Barebones client-side speed-reading application

a guest
Mar 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <html>
  2. <script>
  3. //Author: Jordan Stefanelli
  4. //GPL License: Just kidding. I don't care, this code is awful.
  5.  
  6. // Some global vars that the functions reference.
  7. var g_content = ''; // content = array of split up words from the text area
  8. var g_idx = 0; // the current word to display (the #'d position of the word)
  9. var g_interval = 400; // How many milliseconds to update the word display
  10. var g_running = false; // Track if the application is running
  11. var g_timer = null; // Storage variable for the looping call to update & display words.
  12.  
  13. // Gate-keeper to only allow starting if we're not running.
  14. // Called when clicking "start"
  15. function start_words()
  16. {
  17. if (!g_running)
  18. {
  19. g_running = true;
  20. g_timer = setInterval(flash_words, g_interval);
  21. }
  22. }
  23.  
  24. // Stop the looping call, reset the paragraph position to 0, signal that we are not running.
  25. // Called when clicking 'stop'
  26. function stop_words()
  27. {
  28. if (g_running)
  29. {
  30. g_running = false;
  31. g_idx = 0;
  32. clearInterval(g_timer);
  33. }
  34. }
  35.  
  36. // This is called if you
  37. function set_reading_interval()
  38. {
  39. g_interval = document.getElementsByName('display_interval')[0].value;
  40. update_reading_interval();
  41. }
  42.  
  43. // Called when clicking away from updating the reading interval box
  44. function update_reading_interval()
  45. {
  46. if (g_running)
  47. {
  48. clearInterval(g_timer);
  49. g_running = false;
  50. start_words();
  51. }
  52. }
  53.  
  54. // This is called after you click away from the text box containing your reading content.
  55. function getContent()
  56. {
  57. text = document.getElementsByName('content')[0].value;
  58. g_content = text.split(' ');
  59. }
  60.  
  61. // This method is internally called to update the word display.
  62. function flash_words()
  63. {
  64. word = g_content[g_idx];
  65. document.getElementsByName('display_field')[0].value = word;
  66. g_idx = ( g_idx + 1 ) % g_content.length;
  67. }
  68.  
  69. </script>
  70. <body>
  71. <textarea name="display_interval" onBlur="set_reading_interval();">400</textarea>
  72. <textarea name="content" style="width:400px;height:400px;" onBlur="getContent();"></textarea>
  73. <br>
  74. <textarea style="font-size:200px;font-family:courier new;" name="display_field">test</textarea>
  75. <br>
  76. <input type="button" value="Go." onClick="start_words();flash_words();"></input>
  77. <input type="button" value="Stop." onClick="stop_words();"></input>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement