SpotTheDifference.com cheat

Highlights the solution for the games in SpotTheDifference.com

  1. // ==UserScript==
  2. // @name SpotTheDifference.com cheat
  3. // @author Denilson Sá
  4. // @namespace http://denilson.sa.nom.br/
  5. // @version 1.0
  6. // @description Highlights the solution for the games in SpotTheDifference.com
  7. // @grant none
  8. // @license Public domain
  9. // @include http://www.spotthedifference.com/*
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. var head=document.getElementsByTagName('head')[0];
  14. if( head ) {
  15. var styletext = '';
  16.  
  17. // Photo/Tulip/Buttons/Ladybirds/Books game
  18. var maps = document.getElementsByTagName('map');
  19. if( maps.length > 0 )
  20. {
  21. for(var mapcounter = 0, map; map = maps[mapcounter]; mapcounter++)
  22. {
  23. var framenumber = 0;
  24. if ( map.getAttribute('name') == 'map1' ) framenumber = 0;
  25. else if( map.getAttribute('name') == 'map2' ) framenumber = 1;
  26. else continue;
  27.  
  28. var frame = document.getElementById('frame'+framenumber);
  29. for(var i = 0, area; area = map.childNodes[i]; i++)
  30. {
  31. if( area.nodeType == 1 && area.nodeName.toLowerCase() == 'area' )
  32. {
  33. var coords = area.getAttribute('coords');
  34. if( coords != '0,0,280,360' )
  35. {
  36. coords = coords.split(','); // left-x, top-y, right-x, bottom-y
  37. coords[2] -= coords[0];
  38. coords[3] -= coords[1];
  39. var elem = document.createElement('div');
  40.  
  41. // Commented out because in Firefox the click does not pass
  42. // through this element.
  43. /*
  44. elem.setAttribute('style',
  45. 'position: absolute; '+
  46. 'left: ' +coords[0]+'px; '+
  47. 'top: ' +coords[1]+'px; '+
  48. 'width: ' +coords[2]+'px; '+
  49. 'height: '+coords[3]+'px; '+
  50. 'outline: 2px red dotted;'
  51. );
  52. */
  53.  
  54. elem.setAttribute('style',
  55. 'position: absolute; '+
  56. 'left: '+coords[0]+'px; '+
  57. 'top: ' +coords[1]+'px; '+
  58. 'overflow: visible;'
  59. );
  60.  
  61. // Top border
  62. var border = document.createElement('div');
  63. border.setAttribute('style',
  64. 'position: absolute; '+
  65. 'left: 0px; '+
  66. 'top: 0px; '+
  67. 'width: '+coords[2]+'px; '+
  68. 'border-top: red 2px dotted;'
  69. );
  70. elem.appendChild(border);
  71.  
  72. // Left border
  73. var border = document.createElement('div');
  74. border.setAttribute('style',
  75. 'position: absolute; '+
  76. 'left: 0px; '+
  77. 'top: 0px; '+
  78. 'height: '+coords[3]+'px; '+
  79. 'border-left: red 2px dotted;'
  80. );
  81. elem.appendChild(border);
  82.  
  83. // Right border
  84. var border = document.createElement('div');
  85. border.setAttribute('style',
  86. 'position: absolute; '+
  87. 'left: '+coords[2]+'px; '+
  88. 'top: 0px; '+
  89. 'height: '+coords[3]+'px; '+
  90. 'border-right: red 2px dotted;'
  91. );
  92. elem.appendChild(border);
  93.  
  94. // Bottom border
  95. var border = document.createElement('div');
  96. border.setAttribute('style',
  97. 'position: absolute; '+
  98. 'left: 0px; '+
  99. 'top: '+coords[3]+'px; '+
  100. 'width: '+coords[2]+'px; '+
  101. 'border-bottom: red 2px dotted;'
  102. );
  103. elem.appendChild(border);
  104.  
  105. frame.appendChild(elem);
  106. }
  107. }
  108. }
  109. }
  110. }
  111.  
  112. // GreaseMonkey compatibility (not needed inside Opera)
  113. if( typeof unsafeWindow != 'undefined' )
  114. {
  115. xy = unsafeWindow.xy;
  116. dw = unsafeWindow.dw;
  117. ndiff = unsafeWindow.ndiff;
  118. }
  119.  
  120. // Photo game (but breaks the tulip game)
  121. /*
  122. var icache = document.getElementById('icache2');
  123. if( icache )
  124. {
  125. for(var i = 0; i < ndiff+2; i++)
  126. styletext += '#icache'+i+' { outline: 2px red dotted; }\n';
  127. }
  128. */
  129.  
  130. // Domino/Numbers game
  131. if( typeof xy != 'undefined' )
  132. {
  133. for(var i = 0; i < ndiff; i++)
  134. {
  135. // Domino
  136. styletext += 'img[onmousedown="javascript:return diff('+i+');"] { outline: 2px red dotted; }\n';
  137. // Numbers
  138. styletext += 'div[onmousedown="diff('+i+');"] { outline: 2px red dotted; }\n';
  139. }
  140. }
  141.  
  142. // Text game
  143. if( typeof dw != 'undefined' )
  144. {
  145. for(var i = 0; i < dw.length; i++)
  146. styletext += 'span[onmousedown="javascript:return diff('+dw[i]+');"] { text-decoration: underline; }\n';
  147. }
  148.  
  149. // Adding the style sheet
  150. var style = document.createElement('style');
  151. style.setAttribute('type','text/css');
  152. style.appendChild(document.createTextNode(styletext));
  153. head.appendChild(style);
  154. }
  155. })();