Fontz Quiz Timer & Keyboard Shortcuts

Adds stopwatch to quiz pages; use Ctrl+S to submit and continue on quiz and quiz answer pages

  1. // ==UserScript==
  2. // @name Fontz Quiz Timer & Keyboard Shortcuts
  3. // @namespace http://idlewords.net
  4. // @description Adds stopwatch to quiz pages; use Ctrl+S to submit and continue on quiz and quiz answer pages
  5. // @include http://50.116.7.11:9998/learningQuizController_turk/quiz
  6. // @include http://50.116.7.11:9998/learningQuizController_turk/quiz_answer
  7. // @include http://50.116.7.11:9998/learningQuizController_turk/main_menu
  8. // @version 0.4
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js
  10. // @require https://greasyfork.org/scripts/12377-timecircles/code/TimeCircles.js?version=73868
  11. // @resource customCSS http://git.wimbarelds.nl/TimeCircles/inc/TimeCircles.css
  12. // @grant GM_addStyle
  13. // @grant GM_getResourceText
  14. // ==/UserScript==
  15.  
  16. this.$ = this.jQuery = jQuery.noConflict(true);
  17.  
  18. var keycode = 83; // 83 = S. Change this to a valid code from http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes to change the keyboard shortcut
  19.  
  20. var newCSS = GM_getResourceText ("customCSS");
  21. GM_addStyle (newCSS);
  22.  
  23. $(document).ready(function() {
  24. if (document.location.href == 'http://50.116.7.11:9998/learningQuizController_turk/quiz_answer') {
  25. $(document).keydown(function(event) {
  26. if (event.which == keycode && event.ctrlKey) {
  27. event.preventDefault();
  28. $("input[name='Continue']").click();
  29. }
  30. });
  31. $("form[class='nobox']").after("<p>Questions Completed: " + localStorage.getItem('questions') + "</p>")
  32. }
  33. });
  34.  
  35. $(window).load(function() {
  36. if (document.location.href == 'http://50.116.7.11:9998/learningQuizController_turk/quiz') {
  37. $("div[align='right']").append("<span>" + localStorage.getItem('questions') + "</span>").before(
  38. $("<div></div>")
  39. .css({'height': '200px', 'width': '500', 'align': 'left'})
  40. .addClass('timer')
  41. );
  42. $(".timer").TimeCircles({
  43. time: {
  44. Days: { show: false },
  45. Hours: { show: false },
  46. Minutes: { color: "#BBFFBB" },
  47. Seconds: { color: "#FF9999" }
  48. }
  49. });
  50. $(document).keydown(function(event) {
  51. if (event.which == keycode && event.ctrlKey) {
  52. event.preventDefault();
  53. $(".timer").TimeCircles().stop();
  54. localStorage.setItem('questions', parseInt(localStorage.getItem('questions')) + 1);
  55. $("#submitButton").click();
  56. } else if (event.which == 89 || event.which == 49 || event.which == 97) {
  57. event.preventDefault();
  58. $("#deformfield1-0").prop('checked', true);
  59. } else if (event.which == 78 || event.which == 50 || event.which == 98) {
  60. event.preventDefault();
  61. $("#deformfield1-1").prop('checked', true);
  62. }
  63. });
  64. } else if (document.location.href == 'http://50.116.7.11:9998/learningQuizController_turk/main_menu') {
  65. setTimeout(function(){$('div#bodycontainer p').eq(0).before('Questions Answered: ' + $('circle').length);},1000);
  66. if (localStorage.getItem('questions') === null) {
  67. localStorage.setItem('questions', $('circle').length);
  68. }
  69. }
  70. });