GeoPrinting

Make a better looking print-page on geocaching.com from the normal cache page

  1. // ==UserScript==
  2. // @name GeoPrinting
  3. // @version 2.0.9
  4. // @author Dennis Koot
  5. // @copyright 2018, Dennis Koot
  6. // @namespace https://denniskoot.nl
  7. // @license GPL-3.0+; http://www.gnu.org/licenses/gpl-3.0.txt
  8. // @description Make a better looking print-page on geocaching.com from the normal cache page
  9. // @include https://www.geocaching.com/geocache/*
  10. // @include https://www.geocaching.com/seek/cache_details.aspx*
  11. // @grant none
  12. // @oujs:author koter84
  13. // ==/UserScript==
  14.  
  15. function setupGeoPrinting()
  16. {
  17. doGeoPrinting = function()
  18. {
  19. // remove the print-media css-file
  20. $('link[media="print"]').remove();
  21. $('link[media="screen"]').attr('media', 'all');
  22.  
  23. // hide background images
  24. $('body').attr('background', '');
  25.  
  26. // all text in black
  27. $('body').css('color', '#000000');
  28. $('font').css('color', '#000000');
  29. $('h1, h2, h3, h4, h5, h6').css('color', '#000000');
  30.  
  31. // hide the siteHeader
  32. $('#ctl00_siteHeader').hide();
  33.  
  34. // hide the navigation
  35. $('#gcNavigation').hide();
  36.  
  37. // hide the send_mail_to_owner block
  38. $('.message__owner').hide();
  39.  
  40. // hide the print and download links
  41. $('.DownloadLinks').hide();
  42.  
  43. // larger coordinates
  44. $('#uxLatLon').css('font-size', '18pt');
  45.  
  46. // hide UTM and other conversions
  47. $('#ctl00_ContentBody_LocationSubPanel').hide();
  48. $('#ctl00_ContentBody_lnkConversions').hide();
  49.  
  50. // hide the map
  51. $('#uxlrgMap').hide();
  52.  
  53. // hide the NoPrint
  54. $('.NoPrint').hide();
  55.  
  56. // hide part of the informationWidget
  57. $('.HalfLeft').hide();
  58. $('.EncryptDecrypt').hide();
  59. $('div.InformationWidget p.NoBottomSpacing').hide();
  60.  
  61. // hide the logs
  62. $('#cache_logs_container').hide();
  63.  
  64. // hide the sidebar
  65. $('.sidebar').hide();
  66.  
  67. // fix the width
  68. $('.span-9').width('660px');
  69. $('.span-17').width('100%');
  70.  
  71. // move GC-code a little bit down
  72. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').css('position', 'relative');
  73. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').css('top', '50px');
  74. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').css('margin-top', '-50px');
  75.  
  76. // smaller margins so more fits on one page
  77. $('.Clear').css('margin', '0');
  78. $('.BottomSpacing').css('margin-bottom', '0');
  79. $('.CacheInformationTable').css('margin', '0');
  80. $('.CacheDescriptionHeader').css('margin', '5px 0 0 0');
  81. $('.CacheDetailsPage #Content .container').css('margin-bottom', '0px');
  82.  
  83. // hide the additional hints decryption key
  84. $('#dk').hide();
  85.  
  86. // check if the hint needs to be decrypted
  87. if( $('#ctl00_ContentBody_lnkDH').attr('title') == "Decrypt")
  88. $('#ctl00_ContentBody_lnkDH').click();
  89.  
  90. // hide the generated time etc.
  91. $('.timeago').parent().parent().hide();
  92.  
  93. // remove the scrollback to top
  94. $('#topScroll').remove();
  95.  
  96. // hide the footer
  97. $('footer').hide();
  98.  
  99. // remove <br/>
  100. // $('br').remove();
  101.  
  102. // create a no-geoprint class to show some elements except when printed
  103. $('head').append('<style>@media print { .no-geoprint { display: none !important; } }</style>');
  104.  
  105. // repurpose the disclaimer div
  106. $('.Disclaimer').addClass('no-geoprint');
  107. $('.Disclaimer').html('<strong>Extra Options:</strong>&nbsp;&nbsp;');
  108.  
  109. // add Show/Hide Images
  110. if($('.UserSuppliedContent').find("img").length > 0)
  111. {
  112. //found an image add the "Hide Image" link
  113. $('.Disclaimer').append($('<a href="#">Show/Hide Image(s)</a>').click(function (e) {
  114. e.preventDefault();
  115. $(".UserSuppliedContent").find("img").toggle();
  116. }));
  117. $('.Disclaimer').append('&nbsp;&nbsp;');
  118. }
  119.  
  120. // add Show/Hide Waypoints
  121. $("#ctl00_ContentBody_WaypointsInfo").parent().css('margin', '15px 0 5px 0');
  122. $('.Disclaimer').append($('<a href="#">Show/Hide Waypoint(s)</a>').click(function (e) {
  123. e.preventDefault();
  124. $("#ctl00_ContentBody_WaypointsInfo").parent().toggle();
  125. $("#ctl00_ContentBody_Waypoints").toggle();
  126. }));
  127. $('.Disclaimer').append('&nbsp;&nbsp;');
  128.  
  129. // add Show/Hide Logcounts
  130. $('.Disclaimer').append($('<a href="#">Show/Hide Logcounts</a>').click(function (e) {
  131. e.preventDefault();
  132. $('.InformationWidget').toggle();
  133. }));
  134. $('.Disclaimer').append('&nbsp;&nbsp;');
  135.  
  136. // default above Show/Hide toggles to hide
  137. $(".UserSuppliedContent").find("img").hide();
  138. $("#ctl00_ContentBody_WaypointsInfo").parent().hide();
  139. $("#ctl00_ContentBody_Waypoints").hide();
  140. $('.InformationWidget').hide();
  141.  
  142. // add print-link
  143. $('.Disclaimer').append($('<a href="#" style="float: right;">Print</a>').click(function (e) {
  144. e.preventDefault();
  145. print();
  146. }));
  147.  
  148. $('.Disclaimer').show();
  149. };
  150.  
  151. // insert a GeoPrint-link non-intrusive-style :D
  152. $('#ctl00_ContentBody_lnkPrintFriendly').after(
  153. '&nbsp;<a id="geoprinting_link" class="lnk" href="#" onclick="javascript:doGeoPrinting()">' +
  154. '<span>GeoPrint</span>' +
  155. '</a>&nbsp;');
  156.  
  157. // hide the disclaimer
  158. $('.Disclaimer').hide();
  159. }
  160.  
  161. //var jQueryGeoPrinting = document.createElement("script");
  162. //jQueryGeoPrinting.setAttribute("type", "text/javascript");
  163. //jQueryGeoPrinting.setAttribute("src", "https://code.jquery.com/jquery-latest.js");
  164. //document.body.appendChild(jQueryGeoPrinting);
  165.  
  166. var injectGeoPrinting = document.createElement("script");
  167. injectGeoPrinting.setAttribute("type", "text/javascript");
  168. injectGeoPrinting.appendChild(document.createTextNode("(" + setupGeoPrinting + ")()"));
  169. document.body.appendChild(injectGeoPrinting);