GCHiddenText Redux

Display "hidden text" or "HTML Comments".

  1. // ==UserScript==
  2. // @name GCHiddenText Redux
  3. // @namespace http://userscripts.org/users/201960
  4. // @description Display "hidden text" or "HTML Comments".
  5. // @include *.geocaching.com/geocache/*
  6. // @version 3.2.0
  7. // ==/UserScript==
  8.  
  9.  
  10. /*----------------------History---------------------------------------------------
  11. /*----------------------V3.2.0---------------------------------------------------
  12. v3.2.0 22/11/20
  13. -Added the ability to detect elements with display:none.
  14. -Made searches more efficient.
  15. -Made searches check all types of elements, not just divs.
  16.  
  17. /*----------------------V3.1.0---------------------------------------------------
  18. v3.1.0 27/7/19
  19. -Updated to work on the latest cache pages.
  20. -Created a GitHub repo to manage updates through GreasyFork.
  21.  
  22. /*----------------------V3---------------------------------------------------
  23. v3.0.0 30/9/14
  24. -Started a new life at Greasyfork.
  25. -Removed the USO updater, as it was dead.
  26. -The GeoKrety widget header change didn't make it live in V2.
  27.  
  28. /*----------------------V2---------------------------------------------------
  29. v2.0.2 5/10/13
  30. -Prevented the GeoKrety widget header being detected as hidden text.
  31. v2.0.1 8/9/13
  32. -Added updater.
  33. -Changed back to Chuck's namespace.
  34. v2.0.0 8/9/13
  35. -The GC site had been changed so the include paths no longer worked.
  36.  
  37. /*----------------------V1---------------------------------------------------
  38. v1.3 3/1/11
  39. # fix: Sometimes the Show Hidden Text button would show when no hidden text was present, updated method of checking
  40. # fix: Added to recongize new GC cache page address
  41. v1.2 11/18/10
  42. # new: Finds words, hex and rgb values in white text
  43. # new: Changed to only highlight words and not the whole page
  44. # fix: Updated code to be more sufficient/effective
  45. v1.1.0 9/13/10
  46. # new: Updated to catch white text if use style/font formatting
  47. # fix: Updated error if no Short/Long Description is on the page
  48. v1.0.0 9/10/10 *If you have previous version please uninstall before loading new version
  49. # new:Added auto updater
  50. # new: Updated to be able to show/hide hidden text
  51. # new: updated section of code so user can easily change text/background colors to their preference
  52. v0.0.1 9/7/10
  53. # new: Initial Release (Still testing a couple of options)
  54. */
  55.  
  56. //----------------------SET USER VALUES-------------------------------------------
  57. // Use: color words: white, yellow, etc....
  58. // HEX: #FF45FF ... etc...
  59. // or
  60. // RGB: rgb(255, 255, 255) ... etc....
  61. //
  62. var fgcolor = 'white'; //Forground color for hidden text
  63. var bgcolor = 'red'; //Background color for hidden text
  64. var cm_fgcolor = 'white'; //Foreground color for HTML Comments
  65. var cm_bgcolor = 'green'; //Background color for HTML Comments
  66. //
  67. //----------------------END USER VALUES---------------------------------------
  68.  
  69. //Initialize Constants
  70. var found = false;
  71. var htmlshort = 0,
  72. htmllong = 0;
  73.  
  74. //Check for short or long descriptions
  75. try {
  76. htmlshort = document.getElementById('ctl00_ContentBody_ShortDescription').innerHTML;
  77. } catch (err) {}
  78. try {
  79. htmllong = document.getElementById('ctl00_ContentBody_LongDescription').innerHTML;
  80. } catch (err) {}
  81. var CS,
  82. i;
  83.  
  84. /********Find Hidden Text*********/
  85. //Find Styles Colors
  86. var allStyles = document.evaluate('//*[@style]', document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  87. for (i = 0; i < allStyles.snapshotLength; i++) {
  88. CS = allStyles.snapshotItem(i).style.color.toLowerCase();
  89. // Prevent the GeoKrety widget header being detected as hidden text.
  90. if ((CS == 'white' && allStyles.snapshotItem(i).innerHTML != "Krety") || CS == '#ffffff' || CS == 'rgb(255, 255, 255)') {
  91. found = true;
  92. //set style color values
  93. allStyles.snapshotItem(i).className = 'txt_hidden';
  94. allStyles.snapshotItem(i).style.color = fgcolor;
  95. allStyles.snapshotItem(i).style.backgroundColor = bgcolor;
  96. allStyles.snapshotItem(i).style.display = 'none';
  97. }
  98. }
  99. //Find Font Colors
  100. allStyles = document.evaluate('//*[@color]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  101. for (i = 0; i < allStyles.snapshotLength; i++) {
  102. CS = allStyles.snapshotItem(i).getAttribute('color').toLowerCase();
  103. if (CS == 'white' || CS == '#ffffff') {
  104. found = true;
  105. //remove font color value, to be replaced with style color
  106. allStyles.snapshotItem(i).removeAttribute('color');
  107. //set style color values
  108. allStyles.snapshotItem(i).className = 'txt_hidden';
  109. allStyles.snapshotItem(i).style.color = fgcolor;
  110. allStyles.snapshotItem(i).style.backgroundColor = bgcolor;
  111. allStyles.snapshotItem(i).style.display = 'none';
  112. }
  113. }
  114.  
  115. /*********** Find Comments on Cache Description Page **********/
  116. if (htmlshort) {
  117. var shortdesc = document.evaluate("//span[@id='ctl00_ContentBody_ShortDescription']//comment()", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  118. var cs_length = shortdesc.snapshotLength;
  119. // Look for elements with style set to "visibility: hidden".
  120. var shorthiddendesc = document.evaluate("//span[@id='ctl00_ContentBody_ShortDescription']//*[@style='visibility: hidden']", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  121. var hs_length = shorthiddendesc.snapshotLength;
  122. // Look for elements with style set to "display: none".
  123. var shortnonedesc = document.evaluate(".//span[@id='ctl00_ContentBody_ShortDescription']//*[@style='display: none;']", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  124. var ns_length = shortnonedesc.snapshotLength;
  125. }
  126. if (htmllong) {
  127. var longdesc = document.evaluate("//span[@id='ctl00_ContentBody_LongDescription']//comment()", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  128. var cl_length = longdesc.snapshotLength;
  129. // Look for elements with style set to "visibility: hidden".
  130. var longhiddendesc = document.evaluate("//span[@id='ctl00_ContentBody_LongDescription']//*[@style='visibility: hidden']", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  131. var hl_length = longhiddendesc.snapshotLength;
  132. // Look for elements with style set to "display: none".
  133. var longnonedesc = document.evaluate(".//span[@id='ctl00_ContentBody_LongDescription']//*[@style='display: none;']", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  134. var nl_length = longnonedesc.snapshotLength;
  135. }
  136.  
  137. //Create Elements for Comments
  138. if (cs_length > 0 || cl_length > 0 || hs_length > 0 || ns_length > 0 || hl_length > 0 || nl_length > 0) {
  139. found = true;
  140. for (i = 0; i < cs_length; i++) {
  141. var scs = document.createElement('span');
  142. scs.className = 'txt_hidden';
  143. scs.style.color = cm_fgcolor;
  144. scs.style.backgroundColor = cm_bgcolor;
  145. scs.style.display = 'none';
  146. scs.textContent = shortdesc.snapshotItem(i).data;
  147. shortdesc.snapshotItem(i).parentNode.insertBefore(scs, shortdesc.snapshotItem(i).nextSibling);
  148. }
  149. for (i = 0; i < cl_length; i++) {
  150. var lcs = document.createElement('span');
  151. lcs.className = 'txt_hidden';
  152. lcs.style.color = cm_fgcolor;
  153. lcs.style.backgroundColor = cm_bgcolor;
  154. lcs.style.display = 'none';
  155. lcs.textContent = longdesc.snapshotItem(i).data;
  156. longdesc.snapshotItem(i).parentNode.insertBefore(lcs, longdesc.snapshotItem(i).nextSibling);
  157. }
  158. // Hidden divs.
  159. for (i = 0; i < hs_length; i++) {
  160. var shcs = document.createElement('span');
  161. shcs.className = 'txt_hidden';
  162. shcs.style.color = fgcolor;
  163. shcs.style.backgroundColor = bgcolor;
  164. shcs.style.display = 'none';
  165. shcs.textContent = shorthiddendesc.snapshotItem(i).innerHTML;
  166. shorthiddendesc.snapshotItem(i).parentNode.insertBefore(shcs, shorthiddendesc.snapshotItem(i).nextSibling);
  167. }
  168. for (i = 0; i < hl_length; i++) {
  169. var lhcs = document.createElement('span');
  170. lhcs.className = 'txt_hidden';
  171. lhcs.style.color = fgcolor;
  172. lhcs.style.backgroundColor = bgcolor;
  173. lhcs.style.display = 'none';
  174. lhcs.textContent = longhiddendesc.snapshotItem(i).innerHTML;
  175. longhiddendesc.snapshotItem(i).parentNode.insertBefore(lhcs, longhiddendesc.snapshotItem(i).nextSibling);
  176. }
  177. for (i = 0; i < ns_length; i++) {
  178. var sncs = document.createElement('span');
  179. sncs.className = 'txt_hidden';
  180. sncs.style.color = fgcolor;
  181. sncs.style.backgroundColor = bgcolor;
  182. sncs.style.display = 'none';
  183. sncs.textContent = shortnonedesc.snapshotItem(i).innerHTML;
  184. shortnonedesc.snapshotItem(i).parentNode.insertBefore(sncs, shortnonedesc.snapshotItem(i).nextSibling);
  185. }
  186. for (i = 0; i < nl_length; i++) {
  187. var lncs = document.createElement('span');
  188. lncs.className = 'txt_hidden';
  189. lncs.style.color = fgcolor;
  190. lncs.style.backgroundColor = bgcolor;
  191. lncs.style.display = 'none';
  192. lncs.textContent = longnonedesc.snapshotItem(i).innerHTML;
  193. longnonedesc.snapshotItem(i).parentNode.insertBefore(lncs, longnonedesc.snapshotItem(i).nextSibling);
  194. }
  195. }
  196.  
  197. //Add Found Hidden Text Button
  198. if (found) {
  199. var txt_count = document.getElementsByClassName('txt_hidden');
  200.  
  201. function showtext() {
  202. var i;
  203.  
  204. if (txt_count[0].style.display == '') {
  205. showbutton.value = "Show Hidden Text";
  206. for (i = 0; i < txt_count.length; i++) {
  207. txt_count[i].style.display = 'none';
  208. }
  209. } else {
  210. showbutton.value = "Hide Hidden Text";
  211. for (i = 0; i < txt_count.length; i++) {
  212. txt_count[i].style.display = '';
  213. }
  214. }
  215. }
  216. var showbutton = document.createElement('input');
  217. showbutton.id = "ctl00_ContentBody_btnShowHiddenText";
  218. showbutton.type = "submit";
  219. showbutton.value = "Show Hidden Text";
  220. showbutton.style.color = "red";
  221. showbutton.style.float = "right";
  222. showbutton.setAttribute('onclick', 'return false;');
  223. showbutton.addEventListener('click', showtext, false);
  224. //Insert Button
  225. var dd = document.getElementById('Download').getElementsByTagName('dd')[0];
  226. dd.insertBefore(showbutton, dd.firstChild);
  227. }