MunzeeMap Filter

filter for munzee map

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

  1. // ==UserScript==
  2. // @name MunzeeMap Filter
  3. // @namespace none
  4. // @version 2019.07.22.1952
  5. // @author technical13
  6. // @supportURL https://Discord.me/TheShoeStore
  7. // @include https://www.munzee.com/map*
  8. // @grant GM_getResourceText
  9. // @resource physicals https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/physicals.json
  10. // @resource rovers https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/rovers.json
  11. // @resource POIs https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/POIs.json
  12. // @resource noblast https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/nonblastable.json
  13. // @resource blastable https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/blastable.json
  14. // @resource special https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/specials.json
  15. // @description filter for munzee map
  16. // ==/UserScript==
  17. // jshint esversion: 6
  18. // basedon: MunzeeMapFilterV2 by rynee
  19. // basedon: https://greasyfork.org/en/scripts/11662-munzeemapv2
  20. // basedon: MunzeeMapFilterV3 by CzPeet
  21. // basedon: https://greasyfork.org/en/scripts/-munzeemapv3
  22.  
  23. var isDebug = false;
  24. var intVerbosity = 0;
  25. const ver = '2019.07.22.1952';
  26. const scriptName = 'MunzeeMap Filter v' + ver;
  27.  
  28. function log( intV, strConsole, strLog, ...arrArgs ) {
  29. if ( intV === undefined ) { intV = 0; }
  30. if ( strConsole === undefined ) { strConsole = 'log'; }
  31. if ( strLog === undefined ) { strLog = '%o'; }
  32. if ( intVerbosity >= intV && ( strConsole === 'groupEnd' ) ) { console[ strConsole ](); }
  33. if ( intV === 0 || ( isDebug && intVerbosity >= intV ) ) { console[ strConsole ]( '[%i]: %s: ' + strLog, intV, scriptName, ...arrArgs ); }
  34. }
  35.  
  36. function toBoolean( val ) {
  37. const arrTrue = [ undefined, null, '', true, 'true', 1, '1', 'on', 'yes' ];
  38. val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
  39.  
  40. log( 4, 'log', 'toBoolean() is returning: %o', ( arrTrue.indexOf( val ) !== -1 ? true : false ) );
  41. return ( arrTrue.indexOf( val ) !== -1 ? true : false );
  42. }
  43.  
  44. const intParamsStart = ( document.URL.indexOf( '?' ) + 1 );
  45. const strParams = document.URL.substr( intParamsStart );
  46. const arrParamSets = strParams.split( '&' );
  47. var objParams = {};
  48. arrParamSets.forEach( function( strParam ) {
  49. let arrParam = strParam.split( '=' );
  50. let strParamName = ( arrParam[ 0 ].toLowerCase() || '' );
  51. if ( strParamName === 'verbosity' ) {
  52. isDebug = true;
  53. intVerbosity = ( arrParam[ 1 ] ? ( parseInt( arrParam[ 1 ] ) < 0 ? 0 : ( parseInt( arrParam[ 1 ] ) > 9 ? 9 : parseInt( arrParam[ 1 ] ) ) ) : 9 );
  54. } else if ( strParamName === 'debug' ) {
  55. isDebug = toBoolean( arrParam[ 1 ] );
  56. intVerbosity = 1;
  57. }
  58. } );
  59.  
  60. log( 1, 'warn', 'Debug mode is on with verbosity level: %o', intVerbosity );
  61. log( 1, 'groupCollapsed', 'Verbosity options: (click to expand)' );
  62. log( 1, 'log', '\n\t1) Summary\n\t2) Parameters retrieved from URL\n\t3) Variables set\n\t4) Function returns\n\t9) ALL debugging info and this notice.' );
  63. log( 1, 'groupEnd' );
  64.  
  65. const arrPhysicals = GM_getResourceText( 'physicals' );
  66. const arrBlastables = GM_getResourceText( 'blastable' );
  67. const arrNonBlastables = GM_getResourceText( 'noblast' );
  68. const arrPOI = GM_getResourceText( 'POIs' );
  69. const arrSpecials = GM_getResourceText( 'special' );
  70. const arrRovers = GM_getResourceText( 'rovers' );
  71.  
  72. // $( '#footer' ).remove();
  73. $( 'head' ).append( $( '<style>' +
  74. '.v_blast { border: 2px inset #00FF00; }' +
  75. '.v_non { border: 2px inset #FF0000; }' +
  76. '.v_poi { border: 2px inset #EA6426; }' +
  77. '.physical { border: 2px inset #FF0000; }' +
  78. '.rover { border: 2px double #FF0000; }' +
  79. '.v_special { border: 2px inset #FF6666; }' +
  80. '.ico_show { background-color: #88FF88; }' +
  81. '.ico_hide { opacity: 0.4; background-color: #FF8888; border-style: outset; }' +
  82. '.unknown_type { border-width: 3px; border-style: dashed dotted; border-color: #FF0000; }' +
  83. '.filter_icon { padding: 0px 1px 0px 0px; }' +
  84. '.filter_icon > div { text-align: center; }' +
  85. '.filter_icon > img { height: 30px; cursor: pointer; border-radius: 5px; }' +
  86. '.filter_icon > img.img_hide { opacity: 0.4; }' +
  87. '#filterIcons { padding: 5px; background-color: #FFFFFF; }' +
  88. '#inputbar { background-color: #FFFFFF; top: 30px; border-top: 1px solid #FFFFFF; }' +
  89. '</style>' ) );
  90. $( '.panel.panel-default' ).css( 'margin-bottom', '0px' );
  91. $( '.row' ).css( 'margin', '0px' );
  92. $( '.panel-body' ).css( 'padding-left', '0px' ).css( 'padding-right', '0px' );
  93.  
  94. var inputbar = $( '#inputbar' );
  95. var filterIcons = $( '<div id="filterIcons"></div>' );
  96. inputbar.append( filterIcons );
  97.  
  98. var iconCounter = {};
  99. var objAllIcons = {};
  100. var disabledIcons = [];
  101. var imgSRC = '';
  102.  
  103. function createfilter4Map() {
  104. iconCounter = {};
  105. filterIcons.empty();
  106.  
  107. //Collection
  108. for ( var munzeeID in mapMarkers ) {
  109. //img src
  110. imgSRC = mapMarkers[ munzeeID ]._element.style.backgroundImage.replace( 'url("', '' ).replace( '")', '' );
  111. let strType = imgSRC.split( '/' )[ imgSRC.split( '/' ).length - 1 ].split( '.' )[ 0 ];
  112.  
  113. if ( typeof iconCounter[ imgSRC ] == 'undefined' ) { iconCounter[ imgSRC ] = 1; }
  114. else { iconCounter[ imgSRC ]++; }
  115.  
  116. if ( objAllIcons[ strType ] === undefined ) { objAllIcons[ strType ] = []; }
  117. objAllIcons[ strType ].push( munzeeID );
  118. }
  119.  
  120. //Creation
  121. for ( imgSRC in iconCounter ) {
  122. let strType = imgSRC.split( '/' )[ imgSRC.split( '/' ).length - 1 ].split( '.' )[ 0 ];
  123. let isPhysical = ( arrPhysicals.indexOf( imgSRC ) >= 0 ? true : false );
  124. let isBlastable = ( arrBlastables.indexOf( imgSRC ) >= 0 ? true : false );
  125. let isNonBlastable = ( arrNonBlastables.indexOf( imgSRC ) >= 0 ? true : false );
  126. let isPOI = ( arrPOI.indexOf( imgSRC ) >= 0 ? true : false );
  127. let isSpecial = ( arrSpecials.indexOf( imgSRC ) >= 0 ? true : false );
  128. let isVirtual = ( isNonBlastable || isBlastable || isPOI || isSpecial ? true : false );
  129. let isRover = ( arrRovers.indexOf( imgSRC ) >= 0 ? true : false );
  130.  
  131. if ( isPhysical || isVirtual || isRover ) {
  132. delete objAllIcons[ strType ];
  133. }
  134.  
  135. /* console.log(
  136. 'Virtual: %s\tBlastable: %s\tPOI: %s\tSpecial: %s\tDisabled: %s\tType: %s',
  137. ( isVirtual ? 'yes' : ' no' ), ( isBlastable ? 'yes' : ' no' ),
  138. ( isPOI ? 'yes' : ' no' ), ( isSpecial ? 'yes' : ' no' ),
  139. ( disabledIcons.indexOf( imgSRC ) >= 0 ? 'yes' : ' no' ), strType );//*/
  140.  
  141. //new element
  142. filterIcons.append (
  143. '<div class="pull-left filter_icon">' +
  144. '<div>' + iconCounter[ imgSRC ] + '</div>' +
  145. '<img class="haideris ' + ( isRover ? 'rover ' : ( isVirtual ? ( isBlastable ? 'v_blast ' : 'v_non ' ) + ( isPOI ? 'v_poi ' : '' ) + ( isSpecial ? 'v_special ' : '' ) : ( isPhysical ? 'physical ' : 'unknown_type ' ) ) ) + ( disabledIcons.indexOf( imgSRC ) >= 0 ? 'ico_hide' : 'ico_show' ) + '" src="' + imgSRC + '" />' +
  146. '</div>'
  147. );
  148. }
  149.  
  150. filterIcons.append( '<div style="clear: both; height: 1px; overflow: hidden;"></div>' );
  151.  
  152. updateMapIcons();
  153.  
  154. // Submit GitHub issue for unknown types
  155. var arrAllIconTypes = Object.keys( objAllIcons );
  156. var intAIT = arrAllIconTypes.length;
  157. if ( intAIT > 0 ) {
  158. let isReporter = JSON.parse( localStorage.getItem( 'MMF' ) ).isReporter;
  159. if ( isReporter === null ) {
  160. let beReporter = confirm( scriptName + ' has detected types of Munzees that are not indexed.\n\n\tWould you like to report these to the script owner when found?\n\nSelect OK to report or Cancel to hide these alerts forever¹.' );
  161. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: beReporter } ) );
  162. isReporter = beReporter;
  163. }
  164. if ( isReporter ) {
  165. let doReport = confirm( '[ "' + arrAllIconTypes.join( '", "' ) + '" ] ' + ( intAIT === 1 ? 'is an' : 'are' ) + ' unknown Munzee type' + ( intAIT === 1 ? '' : 's' ) + ' to ' + scriptName + '.\n\n\t\t\tWould you like to let the script writter know about ' + ( intAIT === 1 ? 'it' : 'them' ) + '?' );
  166. if ( doReport ) {
  167. var strTitle = '?title=' + encodeURI( 'Unknown mapMarker(s) detected:' );
  168. var strBody = '&body=' + encodeURI( 'Found unknown mapMarker types:' );
  169. for ( let intTypeIndex in arrAllIconTypes ) {
  170. let strType = arrAllIconTypes[ intTypeIndex ];
  171. let arrList = objAllIcons[ strType ];
  172. let strPinURL = mapMarkers[ arrList[ 0 ] ]._element.style.backgroundImage.replace( 'url("', '' ).replace( '")', '' );
  173. strBody += '%0A%0A' + encodeURI( '![' + strType + '](' + strPinURL + '):' );
  174. for ( var intMunzeeID in arrList ) {
  175. let munzeeID = arrList[ intMunzeeID ];
  176. let objCoords = mapMarkers[ munzeeID ]._lngLat;
  177. let strGeoHash = geohash.encode( objCoords.lat, objCoords.lng,9 );
  178. let strMapLink = 'https://www.munzee.com/map/' + strGeoHash + '/16.0';
  179. strBody += '%0A' + encodeURI( '* [' + objCoords.lat + ', ' + objCoords.lng + '](' + strMapLink + ')' );
  180. }
  181. }
  182. window.open( 'https://github.com/Technical-13/MunzeeMap-Filter/issues/new' + strTitle + strBody, '_blank', 'menubar=no,toolbar=no,location=no,status=no,width=1000' );
  183. } else {
  184. console.info( 'List of unknown types detected: %o', arrAllIconTypes );
  185. let stopReporting = confirm( 'Would you like me to continue asking you to report unknown types?\n\nSelect OK to ask in the future or Cancel to hide these alerts forever¹.' );
  186. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: stopReporting } ) );
  187. }
  188. } else {
  189. console.info( 'List of unknown types detected:\n\t%o\nWould you like to be a reporter when unknown types are found? If so, use the following code here in the console:\n\nlocalStorage.setItem( \'MMF\', JSON.stringify( { isReporter: true } ) );', arrAllIconTypes );
  190. }
  191. }
  192. }
  193.  
  194. function updateMapIcons() {
  195. for ( var mID in mapMarkers ) {
  196. var curr = mapMarkers[ mID ]._element.style.backgroundImage.replace( 'url("', '' ).replace( '")', '' );
  197. if ( $.inArray( curr, disabledIcons ) == -1 ) { $( "[data-index='" + mID + "']" ).css( 'display', 'block' ); }
  198. else { $( "[data-index='" + mID + "']" ).css( 'display', 'none' ); }
  199. }
  200. }
  201.  
  202. // hide
  203. $( document ).on( 'click', '.ico_show.haideris', function ( e ) {
  204. var curr = $( this ).attr( 'src' );
  205.  
  206. if ( e.ctrlKey ) {
  207. var icons = document.querySelectorAll( '.haideris' );
  208. // console.log( 'icons: %o', icons );
  209. disabledIcons = [];
  210. for ( var ic in iconCounter ) {
  211. if ( ic != curr ) { disabledIcons.push( ic ); }
  212. }
  213. // console.log( 'disabledIcons: %o', disabledIcons );
  214.  
  215. for ( var i in icons ) {
  216. // console.log( 'icons[ i ] is a: %o', typeof( icons[ i ] ) );
  217. if ( typeof( icons[ i ] ) === 'object' ) {
  218. let intIcoShowHide = -1;
  219. let strNewClass = Array.from( icons[ i ].classList );
  220. // console.log( 'Testing if `%o` != `%o`: %s', icons[ i ].src, curr, ( icons[ i ].src != curr ? 'NOT ' : '') + 'equal' );
  221. if ( icons[ i ].src != curr ) {
  222. intIcoShowHide = strNewClass.indexOf( 'ico_show' );
  223. strNewClass[ intIcoShowHide ] = 'ico_hide';
  224. } else {
  225. intIcoShowHide = strNewClass.indexOf( 'ico_hide' );
  226. strNewClass[ intIcoShowHide ] = 'ico_show';
  227. }
  228. strNewClass = strNewClass.join( ' ' );
  229. // console.log( 'Replacing classList %o with string `%s`', icons[ i ].classList, strNewClass );
  230. icons[ i ].className = strNewClass;
  231. }
  232. }
  233. }
  234. else {
  235. $( this ).removeClass( 'ico_show' ).addClass( 'ico_hide' );
  236. if ( disabledIcons.indexOf( curr ) == -1 ) { disabledIcons.push( curr ); }
  237. }
  238. updateMapIcons();
  239. } );
  240.  
  241. // show
  242. $( document ).on( 'click', '.ico_hide.haideris', function ( e ) {
  243. var curr = $( this ).attr( 'src' );
  244.  
  245. if ( e.ctrlKey ) {
  246. var icons = document.querySelectorAll( '.haideris' );
  247. // console.log( 'icons: %o', icons );
  248. disabledIcons = [];
  249. for ( var ic in iconCounter ) {
  250. if ( ic == curr ) { disabledIcons.push( ic ); }
  251. }
  252. // console.log( 'disabledIcons: %o', disabledIcons );
  253.  
  254. for ( var i in icons ) {
  255. // console.log( 'icons[ i ] is a: %o', typeof( icons[ i ] ) );
  256. if ( typeof( icons[ i ] ) === 'object' ) {
  257. let intIcoShowHide = -1;
  258. let strNewClass = Array.from( icons[ i ].classList );
  259. // console.log( 'Testing if `%o` != `%o`: %s', icons[ i ].src, curr, ( icons[ i ].src != curr ? 'NOT ' : '') + 'equal' );
  260. if ( icons[ i ].src != curr ) {
  261. intIcoShowHide = strNewClass.indexOf( 'ico_hide' );
  262. strNewClass[ intIcoShowHide ] = 'ico_show';
  263. } else {
  264. intIcoShowHide = strNewClass.indexOf( 'ico_show' );
  265. strNewClass[ intIcoShowHide ] = 'ico_hide';
  266. }
  267. strNewClass = strNewClass.join( ' ' );
  268. // console.log( 'Replacing classList %o with string `%s`', icons[ i ].classList, strNewClass );
  269. icons[ i ].className = strNewClass;
  270. }
  271. }
  272. }
  273. else {
  274. $( this ).removeClass( 'ico_hide' ).addClass( 'ico_show' );
  275. var index = disabledIcons.indexOf( curr );
  276. if ( index !== -1 )
  277. {
  278. disabledIcons.splice( index, 1 );
  279. }
  280. }
  281. updateMapIcons();
  282. } );
  283.  
  284. $( document ).ajaxSuccess( createfilter4Map );