GCHiddenText Redux

Display "hidden text" or "HTML Comments".

当前为 2019-07-27 提交的版本,查看 最新版本

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