GCHiddenText Redux

Display "hidden text" or "HTML Comments".

当前为 2014-09-30 提交的版本,查看 最新版本

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