Greasy Fork is available in English.

Remember itstoohard tries

Shows all attempted tries for all questions so you know what you already tried.

  1. // ==UserScript==
  2. // @name Remember itstoohard tries
  3. // @description Shows all attempted tries for all questions so you know what you already tried.
  4. // @author Bladito
  5. // @version 0.2
  6. // @match http://www.itstoohard.com/puzzle/*
  7. // @namespace Bladito/itstoohard-tries
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @grant GM_addStyle
  10. // ==/UserScript==
  11.  
  12. (function($) {
  13. 'use strict';
  14.  
  15. var storageName = 'Bladito_ith_tries';
  16. var puzzleId = location.href.match(/.*itstoohard.com\/puzzle\/(.*)/)[1];
  17. var tries = getTries();
  18. var lastSubmittedQuestion;
  19.  
  20. GM_addStyle('.one-try { margin-left: 1px; line-height: 10px; display: list-item; list-style-position: inside; list-style-type: circle; }');
  21. GM_addStyle('.already-tried-value { color: red; }');
  22. registerClickEventOnSubmit();
  23. printAlreadyTriedAnswersForAllQuestions();
  24.  
  25. (function(open) {
  26. XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
  27. this.addEventListener("readystatechange", function(event) {
  28. if (this.readyState == 4) {
  29. registerClickEventOnSubmit();
  30. if (event.srcElement.responseText.indexOf('You must wait another') > -1) { //don't remember this try because we need to wait for submit
  31. tries[lastSubmittedQuestion].pop();
  32. }
  33. printAlreadyTriedAnswers(lastSubmittedQuestion);
  34. storeTries();
  35. }
  36. }, false);
  37. open.call(this, method, url, async, user, pass);
  38. };
  39. })(XMLHttpRequest.prototype.open);
  40.  
  41. function registerClickEventOnSubmit() {
  42. $('input[type="submit"').unbind('click.bladito_hook').bind('click.bladito_hook', function(event) {
  43. var $this = $(this);
  44. var questionNumber = parseInt($this.parent()[0].id.replace(/[^0-9]/g, ''), 10);
  45. var $triesForQuestion = $('.tries[question="' + questionNumber + '"]');
  46. var triedValue = $this.prev().val();
  47.  
  48. lastSubmittedQuestion = questionNumber;
  49.  
  50. tries[questionNumber] = tries[questionNumber] || [];
  51. if (tries[questionNumber].indexOf(triedValue) < 0) {
  52. tries[questionNumber].push(triedValue);
  53. } else {
  54. var $alreadyTriedEl = $this.next('.already-tried');
  55. if ($alreadyTriedEl.length) {
  56. $alreadyTriedEl.children('.already-tried-value').text(triedValue);
  57. } else {
  58. $this.after('<p class="already-tried">You\'ve already tried <span class="already-tried-value">' + triedValue + '</span> before! Try something new right away! No time penalty =).</p>');
  59. }
  60. event.preventDefault();
  61. }
  62. });
  63. }
  64.  
  65. function printAlreadyTriedAnswers(questionNumber) {
  66. var wrap = '<div class="tries-wrap"><span>You\'ve already tried '+tries[questionNumber].length+' answers:</span>';
  67. tries[questionNumber].forEach(function(oneTry) {
  68. wrap += '<div class="one-try">' + oneTry + '</div>';
  69. });
  70. wrap += '</div>';
  71.  
  72. $('#M_Repeater_Questions_Panel_Question_' + questionNumber).find('#M_Repeater_Questions_Label_Result_'+(questionNumber)).append(wrap);
  73. }
  74.  
  75. function printAlreadyTriedAnswersForAllQuestions() {
  76. for (var questionNumber in tries) {
  77. printAlreadyTriedAnswers(questionNumber);
  78. }
  79. }
  80.  
  81. function storeTries() {
  82. var triesForAllPuzzles = JSON.parse(localStorage.getItem(storageName)) || {};
  83. triesForAllPuzzles[puzzleId] = tries;
  84. localStorage.setItem(storageName, JSON.stringify(triesForAllPuzzles));
  85. }
  86.  
  87. function getTries() {
  88. var triesForAllPuzzles = JSON.parse(localStorage.getItem(storageName)) || {};
  89. return triesForAllPuzzles[puzzleId] || {};
  90. }
  91.  
  92. })(jQuery);