MunzeeMap Filter

filter for munzee map

当前为 2020-08-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MunzeeMap Filter
  3. // @namespace none
  4. // @version 2020.08.12.1806
  5. // @author technical13
  6. // @supportURL https://Discord.me/TheShoeStore
  7. // @include https://www.munzee.com/*map*
  8. // @include https://www.munzee.com/specials*
  9. // @grant GM_getResourceText
  10. // @resource physicals https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/physicals.json
  11. // @resource rovers https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/rovers.json
  12. // @resource POIs https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/POIs.json
  13. // @resource noblast https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/nonblastable.json
  14. // @resource blastable https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/blastable.json
  15. // @resource special https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/specials.json
  16. // @resource PRBs https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/PRBs.json
  17. // @resource SOBs https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/SOBs.json
  18. // @resource MOSs https://raw.githubusercontent.com/Technical-13/MunzeeMap-Filter/master/MOSs.json
  19. // @description filter for munzee map
  20. // ==/UserScript==
  21. // jshint esversion: 6
  22. // basedon: MunzeeMapFilterV3 by Czimbalmos Péter AKA CzPeet
  23. // basedon: https://greasyfork.org/en/scripts/373493-munzeemapfilterv3
  24. // basedon: MunzeeMapV2 by rynee
  25. // basedon: https://greasyfork.org/en/scripts/11662-munzeemapv2
  26. // basedon: MyMunzeeMap by pkoopmanpk
  27. // basedon: https://greasyfork.org/en/scripts/7062-mymunzeemap
  28. // basedon: MunzeeMap by Nerjuz
  29. // basedon: https://greasyfork.org/en/scripts/4750-munzeemap
  30.  
  31. var isDebug = false;
  32. var intVerbosity = 0;
  33. const ver = '2020.08.12.1806';
  34. const scriptName = 'MunzeeMap Filter v' + ver;
  35. console.info( scriptName + ' loaded' );
  36. var lastNominatimRequest = ( new Date() ).valueOf();
  37.  
  38. function log( intV, strConsole, strLog, ...arrArgs ) {
  39. if ( intV === undefined ) { intV = 0; }
  40. if ( strConsole === undefined ) { strConsole = 'log'; }
  41. if ( strLog === undefined ) { strLog = '%o'; }
  42. if ( intVerbosity >= intV && ( strConsole === 'groupEnd' ) ) { console[ strConsole ](); }
  43. if ( intV === 0 || ( isDebug && intVerbosity >= intV ) ) { console[ strConsole ]( '[%i]: %s: ' + strLog, intV, scriptName, ...arrArgs ); }
  44. }
  45.  
  46. function toBoolean( val ) {
  47. const arrTrue = [ undefined, null, '', true, 'true', 1, '1', 'on', 'yes' ];
  48. val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
  49.  
  50. log( 4, 'log', 'toBoolean() is returning: %o', ( arrTrue.indexOf( val ) !== -1 ? true : false ) );
  51. return ( arrTrue.indexOf( val ) !== -1 ? true : false );
  52. }
  53.  
  54. const intParamsStart = ( document.URL.indexOf( '?' ) + 1 );
  55. const strParams = document.URL.substr( intParamsStart );
  56. const arrParamSets = strParams.split( '&' );
  57. var objParams = {};
  58. arrParamSets.forEach( function( strParam ) {
  59. let arrParam = strParam.split( '=' );
  60. let strParamName = ( arrParam[ 0 ].toLowerCase() || '' );
  61. if ( strParamName === 'verbosity' ) {
  62. isDebug = true;
  63. intVerbosity = ( arrParam[ 1 ] ? ( parseInt( arrParam[ 1 ] ) < 0 ? 0 : ( parseInt( arrParam[ 1 ] ) > 9 ? 9 : parseInt( arrParam[ 1 ] ) ) ) : 9 );
  64. } else if ( strParamName === 'debug' ) {
  65. isDebug = toBoolean( arrParam[ 1 ] );
  66. intVerbosity = 1;
  67. }
  68. } );
  69.  
  70. log( 1, 'warn', 'Debug mode is on with verbosity level: %o', intVerbosity );
  71. log( 1, 'groupCollapsed', 'Verbosity options: (click to expand)' );
  72. 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.' );
  73. log( 1, 'groupEnd' );
  74.  
  75. function convertToHex( str ) { var hex = ''; for ( var i = 0; i < str.length; i++ ) { hex += '' + str.charCodeAt( i ).toString( 16 ); } return hex; }
  76. const key = 'pk.8e' + convertToHex( '¸3þˆÿ¯}¤ê’' ).replace( '43', '403' ).toString();
  77.  
  78. const arrPhysicals = JSON.parse( GM_getResourceText( 'physicals' ) ).arrPhysicals;
  79. const arrBlastables = JSON.parse( GM_getResourceText( 'blastable' ) ).arrBlastables;
  80. const arrNonBlastables = JSON.parse( GM_getResourceText( 'noblast' ) ).arrNonBlastables;
  81. const arrPOI = JSON.parse( GM_getResourceText( 'POIs' ) ).arrPOI;
  82. const arrPRB = JSON.parse( GM_getResourceText( 'PRBs' ) ).arrPRBs;
  83. const arrSOB = JSON.parse( GM_getResourceText( 'SOBs' ) ).arrSOBs;
  84. const arrMOS = JSON.parse( GM_getResourceText( 'MOSs' ) ).arrMOSs;
  85. const arrSpecial = JSON.parse( GM_getResourceText( 'special' ) ).arrSpecials;
  86. const arrSpecials = arrSpecial.concat( arrPRB, arrSOB, arrMOS );
  87. const arrRovers = JSON.parse( GM_getResourceText( 'rovers' ) ).arrRovers;
  88. const arrDestination = [ 'https://munzee.global.ssl.fastly.net/images/pins/hotel.png', 'https://munzee.global.ssl.fastly.net/images/pins/motel.png',
  89. 'https://munzee.global.ssl.fastly.net/images/pins/timesharemunzee.png', 'https://munzee.global.ssl.fastly.net/images/pins/virtual_resort.png',
  90. 'https://munzee.global.ssl.fastly.net/images/pins/treehouse.png', 'https://munzee.global.ssl.fastly.net/images/pins/treehouse1.png' ,
  91. 'https://munzee.global.ssl.fastly.net/images/pins/treehouse2.png', 'https://munzee.global.ssl.fastly.net/images/pins/treehouse3.png' ,
  92. 'https://munzee.global.ssl.fastly.net/images/pins/treehouse4.png', 'https://munzee.global.ssl.fastly.net/images/pins/treehouse5.png' ,
  93. 'https://munzee.global.ssl.fastly.net/images/pins/treehouse6.png', 'https://munzee.global.ssl.fastly.net/images/pins/skyland.png',
  94. 'https://munzee.global.ssl.fastly.net/images/pins/skyland1.png', 'https://munzee.global.ssl.fastly.net/images/pins/skyland2.png',
  95. 'https://munzee.global.ssl.fastly.net/images/pins/skyland3.png', 'https://munzee.global.ssl.fastly.net/images/pins/skyland4.png',
  96. 'https://munzee.global.ssl.fastly.net/images/pins/skyland5.png', 'https://munzee.global.ssl.fastly.net/images/pins/skyland6.png' ];
  97. const arrTrail = [ 'https://munzee.global.ssl.fastly.net/images/pins/trail.png', 'https://munzee.global.ssl.fastly.net/images/pins/virtual_trail.png' ];
  98. var arrReported = ( !localStorage.getItem( 'MMF' ) ? [] : JSON.parse( localStorage.getItem( 'MMF' ) ).arrReported );
  99.  
  100. var isReporter = ( !localStorage.getItem( 'MMF' ) ? null : JSON.parse( localStorage.getItem( 'MMF' ) ).isReporter );
  101. if ( isReporter === null ) {
  102. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: false, arrReported: [] } ) );
  103. isReporter = false;
  104. }
  105.  
  106. function showAddress() {
  107. var lat = map.getCenter().lat, lon = map.getCenter().lng, zoom = map.getZoom();
  108. var intZoom = Math.round( zoom < 3 ? 3 : ( zoom > 18 ? 18 : zoom ) );
  109. var geoHash = geohash.encode( lat, lon, 9 );
  110. $( 'span#address-coords' ).text( '( ' + lat + ', ' + lon + ' )' );
  111. $( 'a#address-google' ).attr( 'href', 'https://www.google.com/maps/place/@' + lat + ',' + lon + ',' + zoom + 'z' );
  112. $( 'a#address-permalink' ).attr( 'href', 'https://www.munzee.com/map/' + geoHash + '/' + zoom );
  113. var intRequestNow = ( new Date() ).valueOf();
  114. log( 2, 'log', 'Attempting to get address %oms from last request:\n\t%s >= %s', ( intRequestNow - lastNominatimRequest ), intRequestNow, lastNominatimRequest );
  115. if ( intRequestNow >= lastNominatimRequest ) {
  116. log( 2, 'log', 'Attempting to get address %oms from last request.', ( intRequestNow - lastNominatimRequest ) );
  117. lastNominatimRequest = ( intRequestNow + 1500 );
  118. $.get( 'https://us1.locationiq.com/v1/reverse.php?key=' + key + '&format=json&namedetails=1&extratags=1&lat=' + lat + '&lon=' + lon + '&zoom=' + ( intZoom > 18 ? 18 : ( intZoom < 3 ? 3 : intZoom ) ) ).done( function ( data ) {
  119. log( 2, 'log', 'https://us1.locationiq.com/v1/reverse.php?key=%s&format=json&namedetails=1&extratags=1&lat=%s&lon=%s&zoom=%s result:\n\t%o', key, lat, lon, intZoom, data );
  120. if ( $( 'span#address-section' ).is( ':hidden' ) ) { $( 'span#address-section' ).show() }
  121. $( 'span#address-text' ).text( data.display_name );
  122. } ).fail( function ( errGet ) {
  123. $( 'span#address-text' ).hide();
  124. if ( errGet.status != 0 ) {
  125. log( 0, 'error', 'Failed to get:\nhttps://us1.locationiq.com/v1/reverse.php?key=%s&format=json&namedetails=1&extratags=1&lat=%s&lon=%s&zoom=%s:\n\t%o', key, lat, lon, intZoom, errGet );
  126. } else {
  127. log( 0, 'error', 'https://us1.locationiq.com/v1/reverse.php?key=%s&format=json&namedetails=1&extratags=1&lat=%s&lon=%s&zoom=%s blocked by rate limiting.', key, lat, lon, intZoom );
  128. lastNominatimRequest = ( intRequestNow + 300000 );
  129. }
  130. } );
  131. }
  132. }
  133.  
  134. var lat = map.getCenter().lat, lon = map.getCenter().lng, zoom = map.getZoom();
  135. var geoHash = geohash.encode( lat, lon, 9 );
  136. var mapLocationSection = document.createElement( 'div' );
  137. mapLocationSection.id = 'address';
  138. mapLocationSection.style = 'text-align: center;';
  139. var mapAddress = document.createElement( 'span' );
  140. mapAddress.id = 'address-section';
  141. var mapAddressText = document.createElement( 'span' );
  142. mapAddressText.id = 'address-text';
  143. var mapAddressAttributionLink = document.createElement( 'a' );
  144. mapAddressAttributionLink.id = 'address-text-attribution-link';
  145. mapAddressAttributionLink.innerText = 'LocationIQ';
  146. mapAddressAttributionLink.href = 'https://locationiq.com/attribution';
  147. var mapAddressAttribution = document.createElement( 'small' );
  148. mapAddressAttribution.id = 'address-text-attribution';
  149. mapAddressAttribution.append( document.createTextNode( ' (address provided by: ' ), mapAddressAttributionLink, document.createTextNode( ')' ) );
  150. mapAddress.append( mapAddressText, mapAddressAttribution );
  151. var mapCoords = document.createElement( 'span' );
  152. mapCoords.id = 'address-coords';
  153. mapCoords.innerText = '( ' + lat + ', ' + lon + ' )';
  154. var mapGoogle = document.createElement( 'a' );
  155. mapGoogle.id = 'address-google';
  156. mapGoogle.innerText = 'Google Maps';
  157. mapGoogle.href = 'https://www.google.com/maps/place/@' + lat + ',' + lon + ',' + zoom + 'z';
  158. var mapLink = document.createElement( 'a' );
  159. mapLink.id = 'address-permalink';
  160. mapLink.innerText = 'Munzee Permalink';
  161. mapLink.href = 'https://www.munzee.com/map/' + geoHash + '/' + zoom;
  162. /*var mapMVGP = document.createElement( 'a' );
  163. mapMVGP.id = 'address-mvgp';
  164. mapMVGP.href = 'https://www.munzee.com/map/' + geoHash + '/' + zoom;
  165. var mapMVGPAbbr = document.createElement( 'abbr' );
  166. mapMVGPAbbr.title = 'Munzee Virtual Garden Painter';
  167. mapMVGPAbbr.innerText = 'MVGP';
  168. mapMVGP.append( mapMVGPAbbr );//*/
  169.  
  170. mapLocationSection.append( mapAddress, document.createElement( 'br' ),
  171. mapCoords, document.createTextNode( ' -> ' ),
  172. mapGoogle, document.createTextNode( ' - ' ),
  173. mapLink );
  174. //mapLocationSection.append( document.createTextNode( ' ' ) );
  175. //mapLocationSection.append( mapMVGP );
  176.  
  177. showAddress();
  178.  
  179. // $( '#footer' ).remove();
  180. $( 'head' ).append(
  181. $( '<style>' +
  182. '.v_blast { border: 2px inset #00FF00; }' +// green
  183. '.v_non { border: 2px inset #FF0000; }' +// red
  184. '.v_poi { border: 2px inset #EA6426; }' +// POI orange
  185. '.physical { border: 2px inset #330000; }' +// maroon
  186. '.rover { border: 2px double #006600; }' +// dark green
  187. '.v_special { border: 2px inset #FF00FF; }' +// Purple
  188. '.ico_show { background-color: #88FF88; }' +
  189. '.ico_hide { opacity: 0.4; background-color: #FF8888; border-style: outset; }' +
  190. '.reported { border-width: 3px; border-style: dashed dotted; border-color: #FFFF00; }' +// yellow
  191. '.unknown_type { border-width: 3px; border-style: dashed dotted; border-color: #FF0000; }' +// red
  192. '.filter_icon { padding: 0px 1px 0px 0px; }' +
  193. '.filter_icon > div { text-align: center; }' +
  194. '.filter_icon > img { height: 30px; cursor: pointer; border-radius: 5px; }' +
  195. '.filter_icon > img.img_hide { opacity: 0.4; }' +
  196. '#filterIcons { padding: 5px; background-color: #FFFFFF; }' +
  197. '#inputbar { background-color: #FFFFFF; top: 30px; border-top: 1px solid #FFFFFF; }' +
  198. '</style>'
  199. )
  200. );
  201. $( '.panel.panel-default' ).css( 'margin-bottom', '0px' );
  202. $( '.row' ).css( 'margin', '0px' );
  203. $( '.panel-body' ).css( 'padding-left', '0px' ).css( 'padding-right', '0px' );
  204.  
  205. var inputbar = $( '#inputbar' );
  206. var filterButtons = $( '<br style="line-height: 3em;"><div id="filterButtons" class="btn-group" data-toggle="buttons">' +
  207. '<label class="btn btn-success"><input id="check_blastable" type="checkbox">hide blastable</label>' +
  208. '<br class="visible-xs">' +
  209. '<label class="btn btn-success"><input id="check_non_blastable" type="checkbox">hide non-blastable</label>' +
  210. '<br class="visible-xs">' +
  211. '<label class="btn btn-success"><input id="check_poi" type="checkbox">hide POI</label>' +
  212. '<br class="visible-xs">' +
  213. '<label class="btn btn-info"><input id="be_reporter" type="checkbox">show reporting</label>' +
  214. '</div>' );
  215. inputbar.prepend( filterButtons );
  216. var filterIcons = $( '<div id="filterIcons"></div>' );
  217. inputbar.prepend( filterIcons );
  218. if ( isReporter ) {
  219. toggleAction( $( '#be_reporter' ) );
  220. $( '#be_reporter' ).parent().addClass( 'active' );
  221. }
  222.  
  223. var objAllMunzees = {};
  224. var iconCounter = {};
  225. var objAllIcons = {};
  226. var disabledIcons = [];
  227. var imgSRC = '';
  228.  
  229. function updateMapIcons() {
  230. showAddress();
  231. for ( var mID in mapMarkers ) {
  232. var curr = mapMarkers[ mID ]._element.style.backgroundImage.replace( 'url("', '' ).replace( '")', '' );
  233. if ( $.inArray( curr, disabledIcons ) == -1 ) { $( "[data-index='" + mID + "']" ).css( 'display', 'block' ); }
  234. else { $( "[data-index='" + mID + "']" ).css( 'display', 'none' ); }
  235. }
  236. }
  237. function submitNewTypes() {
  238. var arrAllIconTypes = Object.keys( objAllIcons );
  239. var intAIT = arrAllIconTypes.length;
  240. if ( intAIT > 0 ) {
  241. if ( isReporter ) {
  242. 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' ) + '?' );
  243. if ( doReport ) {
  244. var arrReporting = [];
  245. var strTitle = '?title=' + encodeURIComponent( 'Unknown type' + ( arrAllIconTypes.length === 1 ? '' : 's' ) + ': ' );
  246. var strBody = '&body=' + encodeURIComponent( 'Found unknown mapMarker types:' );
  247. for ( let intTypeIndex in arrAllIconTypes ) {
  248. let strType = arrAllIconTypes[ intTypeIndex ];
  249. let arrList = objAllIcons[ strType ];
  250. let strPinURL = objAllMunzees[ arrList[ 0 ] ].type_id;
  251. arrReporting.push( strPinURL );
  252. let strPinType = ( objAllMunzees[ arrList[ 0 ] ].is_virtual == 1 ? 'virtual' : 'physical' );
  253. if ( intTypeIndex >= 1 ) { strTitle += ', '; }
  254. strTitle += encodeURIComponent( '[ "' + strPinType + '", "' + strType + '" ]' );
  255. strBody += '%0A%0A' + encodeURIComponent( strPinURL + ' is a ' + strPinType + ': ![' + strType + '](' + strPinURL + ')' );
  256. var arrReports = [];
  257. for ( var intMunzeeID in arrList ) {
  258. let munzeeID = arrList[ intMunzeeID ];
  259. // console.info( 'Created link for: %o', objAllMunzees[ munzeeID ] );
  260. if ( arrReports.indexOf( munzeeID ) === -1 ) {
  261. arrReports.push( munzeeID );
  262. let strMunzeeOwnerLink = '[' + objAllMunzees[ munzeeID ].user + '](https://www.munzee.com/m/' + objAllMunzees[ munzeeID ].user + ')';
  263. // console.log( 'strMunzeeOwnerLink: %o', strMunzeeOwnerLink );
  264. let strMunzeeLink = '[' + objAllMunzees[ munzeeID ].name + '](https://www.munzee.com/m/' + objAllMunzees[ munzeeID ].user + '/' + objAllMunzees[ munzeeID ].number + ')';
  265. // console.log( 'strMunzeeLink: %o', strMunzeeLink );
  266. let strGeoHash = geohash.encode( objAllMunzees[ munzeeID ].lat, objAllMunzees[ munzeeID ].lon, 9 );
  267. // console.log( 'strGeoHash: %o', strGeoHash );
  268. let strMapLink = '[' + objAllMunzees[ munzeeID ].lat + ', ' + objAllMunzees[ munzeeID ].lon + '](https://www.munzee.com/map/' + strGeoHash + '/20.0)';
  269. // console.log( 'strMapLink: %o', strMapLink );
  270. strBody += '%0A' + encodeURIComponent( '* ' + strMunzeeLink + ' at ' + strMapLink + ' by ' + strMunzeeOwnerLink );
  271. // console.log( '+strBody: %o', '%0A' + encodeURIComponent( '* ' + strMunzeeLink + ' at ' + strMapLink + ' by ' + strMunzeeOwnerLink ) );
  272. }
  273. }
  274. }
  275. window.open( 'https://github.com/Technical-13/MunzeeMap-Filter/issues/new' + strTitle + strBody, '_blank', 'menubar=no,toolbar=no,location=no,status=no,width=1000' );
  276. arrReported = arrReported.concat( arrReporting );
  277. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: isReporter, arrReported: arrReported } ) );
  278. } else {
  279. log( 2, 'info', 'List of unknown types detected: %o', arrAllIconTypes );
  280. }
  281. } else {
  282. log( 2, 'info', 'List of unknown types detected:\n\t%o', arrAllIconTypes );
  283. }
  284. }
  285. }// Submit GitHub issue for unknown types
  286. function toggleAction( target, isInverted = false ) {
  287. let isChecked = target.checked;
  288. if ( isInverted ) { isChecked = !isChecked; }
  289. let strOldAction = ( isChecked ? 'hide' : 'show' );
  290. let strNewAction = ( isChecked ? 'show' : 'hide' );
  291. $( target ).parent().html( $( target ).parent().html().replace( strOldAction, strNewAction ) );
  292. }
  293. function createfilter4Map( event, xhr, settings ) {
  294. var munzeeData = xhr.responseJSON;
  295. $.each( mapMarkers, function ( key, marker ) {
  296. $.each( munzeeData, function( box_key, element ) {
  297. if ( element.munzee_id == key ) {
  298. objAllMunzees[ key ] = element;
  299. }
  300. } );
  301. } );
  302.  
  303. iconCounter = {};
  304. filterIcons.empty();
  305.  
  306. //Collection
  307. for ( var munzeeID in mapMarkers ) {
  308. //img src
  309. imgSRC = mapMarkers[ munzeeID ]._element.style.backgroundImage.replace( 'url("', '' ).replace( '")', '' );
  310. let strType = imgSRC.split( '/' )[ imgSRC.split( '/' ).length - 1 ].split( '.' )[ 0 ];
  311.  
  312. if ( typeof iconCounter[ imgSRC ] == 'undefined' ) { iconCounter[ imgSRC ] = 1; }
  313. else { iconCounter[ imgSRC ]++; }
  314.  
  315. if ( objAllIcons[ strType ] === undefined ) { objAllIcons[ strType ] = []; }
  316. if ( objAllIcons[ strType ].indexOf( munzeeID ) === -1 ) { objAllIcons[ strType ].push( munzeeID ); }
  317. }
  318.  
  319. //Creation
  320. for ( imgSRC in iconCounter ) {
  321. let strType = imgSRC.split( '/' )[ imgSRC.split( '/' ).length - 1 ].split( '.' )[ 0 ];
  322. let isPhysical = ( arrPhysicals.indexOf( imgSRC ) >= 0 ? true : false );
  323. let isBlastable = ( arrBlastables.indexOf( imgSRC ) >= 0 ? true : false );
  324. let isNonBlastable = ( arrNonBlastables.indexOf( imgSRC ) >= 0 ? true : false );
  325. let isPOI = ( arrPOI.indexOf( imgSRC ) >= 0 ? true : false );
  326. let isSpecial = ( arrSpecials.indexOf( imgSRC ) >= 0 ? true : false );
  327. let isVirtual = ( isNonBlastable || isBlastable || isPOI || isSpecial ? true : false );
  328. let isRover = ( arrRovers.indexOf( imgSRC ) >= 0 ? true : false );
  329. let isReported = ( arrReported.indexOf( imgSRC ) >= 0 ? true : false );
  330.  
  331. let arrDebug = arrDestination.concat( arrTrail );
  332. if ( arrDebug.indexOf( imgSRC ) >= 0 ) {
  333. log( 1, 'log', 'Debugging: %o', objAllMunzees[ objAllIcons[ strType ][ 0 ] ] );
  334. }
  335.  
  336. if ( isPhysical || isVirtual || isRover || isReported ) {
  337. delete objAllIcons[ strType ];
  338. if ( isReported && ( isPhysical || isVirtual || isRover ) ) {
  339. arrReported = arrReported.splice( arrReported.indexOf( imgSRC ), 1 );
  340. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: isReporter, arrReported: arrReported } ) );
  341. }
  342. }
  343.  
  344. /* console.log(
  345. 'Virtual: %s\tBlastable: %s\tPOI: %s\tSpecial: %s\tDisabled: %s\tType: %s',
  346. ( isVirtual ? 'yes' : ' no' ), ( isBlastable ? 'yes' : ' no' ),
  347. ( isPOI ? 'yes' : ' no' ), ( isSpecial ? 'yes' : ' no' ),
  348. ( disabledIcons.indexOf( imgSRC ) >= 0 ? 'yes' : ' no' ), strType );//*/
  349.  
  350. //new element
  351. filterIcons.append (
  352. '<div class="pull-left filter_icon">' +
  353. '<div>' + iconCounter[ imgSRC ] + '</div>' +
  354. '<img class="haideris ' + ( isRover ? 'rover ' : ( isVirtual ? ( isBlastable ? 'v_blast ' : 'v_non ' ) + ( isPOI ? 'v_poi ' : '' ) + ( isSpecial ? 'v_special ' : '' ) : ( isPhysical ? 'physical v_non ' : ( isReported ? 'reported ' : 'unknown_type ' ) ) ) ) + ( disabledIcons.indexOf( imgSRC ) >= 0 ? 'ico_hide' : 'ico_show' ) + '" src="' + imgSRC + '" title="' + strType + '" />' +
  355. '</div>'
  356. );
  357. }
  358.  
  359. filterIcons.append( '<div style="clear: both; height: 1px; overflow: hidden;"></div>' );
  360.  
  361. updateMapIcons();
  362.  
  363. submitNewTypes();
  364. }
  365.  
  366. if ( ( new RegExp( 'specials' ) ).test( window.location.pathname ) ) {
  367. log( 1, 'log', 'Detected page: specials' );
  368. $( document ).on( 'mouseup', '#map_span', function( e ) { showAddress(); } );
  369. $( document ).on( 'click', '#map-box-specials-zoom-in', function( e ) { showAddress(); } );
  370. $( document ).on( 'click', '#map-box-specials-zoom-out', function( e ) { showAddress(); } );
  371. $( 'div#map_span' ).after( mapLocationSection );
  372. }
  373. else if ( window.location.pathname.split( '/' )[ 1 ] === 'map' ) {
  374. log( 1, 'log', 'Detected page: map' );
  375. $( 'div#inputbar' ).before( mapLocationSection );
  376. $( document ).on( 'click', '.ico_show.haideris', function ( e ) {
  377. var curr = $( this ).attr( 'src' );
  378.  
  379. if ( e.ctrlKey ) {
  380. var icons = document.querySelectorAll( '.haideris' );
  381. // console.log( 'icons: %o', icons );
  382. disabledIcons = [];
  383. for ( var ic in iconCounter ) {
  384. if ( ic != curr ) { disabledIcons.push( ic ); }
  385. }
  386. // console.log( 'disabledIcons: %o', disabledIcons );
  387.  
  388. for ( var i in icons ) {
  389. // console.log( 'icons[ i ] is a: %o', typeof( icons[ i ] ) );
  390. if ( typeof( icons[ i ] ) === 'object' ) {
  391. let intIcoShowHide = -1;
  392. let strNewClass = Array.from( icons[ i ].classList );
  393. // console.log( 'Testing if `%o` != `%o`: %s', icons[ i ].src, curr, ( icons[ i ].src != curr ? 'NOT ' : '') + 'equal' );
  394. if ( icons[ i ].src != curr ) {
  395. intIcoShowHide = strNewClass.indexOf( 'ico_show' );
  396. strNewClass[ intIcoShowHide ] = 'ico_hide';
  397. } else {
  398. intIcoShowHide = strNewClass.indexOf( 'ico_hide' );
  399. strNewClass[ intIcoShowHide ] = 'ico_show';
  400. }
  401. strNewClass = strNewClass.join( ' ' );
  402. // console.log( 'Replacing classList %o with string `%s`', icons[ i ].classList, strNewClass );
  403. icons[ i ].className = strNewClass;
  404. }
  405. }
  406. }
  407. else {
  408. $( this ).removeClass( 'ico_show' ).addClass( 'ico_hide' );
  409. if ( disabledIcons.indexOf( curr ) == -1 ) { disabledIcons.push( curr ); }
  410. }
  411. updateMapIcons();
  412. } );// hide
  413. $( document ).on( 'click', '.ico_hide.haideris', function ( e ) {
  414. var curr = $( this ).attr( 'src' );
  415.  
  416. if ( e.ctrlKey ) {
  417. var icons = document.querySelectorAll( '.haideris' );
  418. // console.log( 'icons: %o', icons );
  419. disabledIcons = [];
  420. for ( var ic in iconCounter ) {
  421. if ( ic == curr ) { disabledIcons.push( ic ); }
  422. }
  423. // console.log( 'disabledIcons: %o', disabledIcons );
  424.  
  425. for ( var i in icons ) {
  426. // console.log( 'icons[ i ] is a: %o', typeof( icons[ i ] ) );
  427. if ( typeof( icons[ i ] ) === 'object' ) {
  428. let intIcoShowHide = -1;
  429. let strNewClass = Array.from( icons[ i ].classList );
  430. // console.log( 'Testing if `%o` != `%o`: %s', icons[ i ].src, curr, ( icons[ i ].src != curr ? 'NOT ' : '') + 'equal' );
  431. if ( icons[ i ].src != curr ) {
  432. intIcoShowHide = strNewClass.indexOf( 'ico_hide' );
  433. strNewClass[ intIcoShowHide ] = 'ico_show';
  434. } else {
  435. intIcoShowHide = strNewClass.indexOf( 'ico_show' );
  436. strNewClass[ intIcoShowHide ] = 'ico_hide';
  437. }
  438. strNewClass = strNewClass.join( ' ' );
  439. // console.log( 'Replacing classList %o with string `%s`', icons[ i ].classList, strNewClass );
  440. icons[ i ].className = strNewClass;
  441. }
  442. }
  443. }
  444. else {
  445. $( this ).removeClass( 'ico_hide' ).addClass( 'ico_show' );
  446. var index = disabledIcons.indexOf( curr );
  447. if ( index !== -1 ) { disabledIcons.splice( index, 1 ); }
  448. }
  449. updateMapIcons();
  450. } );// show
  451. $( document ).on( 'change', '#check_blastable', function( e ) {
  452. toggleAction( e.target );
  453. for ( var intCurr in arrBlastables ) {
  454. var curr = arrBlastables[ intCurr ];
  455. // console.log( '%d:%s: %o', intCurr, curr, arrBlastables );
  456.  
  457. if ( e.target.checked ) {
  458. // console.log( 'Hiding: %o', curr );
  459. $( '.v_blast.ico_show.haideris' ).removeClass( 'ico_show' ).addClass( 'ico_hide' );
  460. if ( disabledIcons.indexOf( curr ) == -1 ) { disabledIcons.push( curr ); }
  461. } else {
  462. // console.log( 'Showing: %o', curr );
  463. $( '.v_blast.ico_hide.haideris' ).removeClass( 'ico_hide' ).addClass( 'ico_show' );
  464. var index = disabledIcons.indexOf( curr );
  465. if ( index !== -1 ) { disabledIcons.splice( index, 1 ); }
  466. }
  467. }
  468. updateMapIcons();
  469. } );// blastable
  470. $( document ).on( 'change', '#check_non_blastable', function( e ) {
  471. toggleAction( e.target );
  472. if ( $( '#check_poi' )[ 0 ].parentNode.innerText.indexOf( 'show' ) !== -1 ) {
  473. if ( !e.target.checked ) {
  474. $( '#check_poi' ).click();
  475. }
  476. } else if ( e.target.checked ) {
  477. $( '#check_poi' ).click();
  478. }
  479. var arrAllNonBlastables = arrNonBlastables.concat( arrPOI, arrPhysicals, arrRovers );
  480. for ( var intCurr in arrAllNonBlastables ) {
  481. var curr = arrAllNonBlastables[ intCurr ];
  482. // console.log( '%d:%s: %o', intCurr, curr, arrBlastables );
  483.  
  484. if ( e.target.checked ) {
  485. // console.log( 'Hiding: %o', curr );
  486. $( '.v_non.ico_show.haideris' ).removeClass( 'ico_show' ).addClass( 'ico_hide' );
  487. if ( disabledIcons.indexOf( curr ) == -1 ) { disabledIcons.push( curr ); }
  488. } else {
  489. // console.log( 'Showing: %o', curr );
  490. $( '.v_non.ico_hide.haideris' ).removeClass( 'ico_hide' ).addClass( 'ico_show' );
  491. var index = disabledIcons.indexOf( curr );
  492. if ( index !== -1 ) { disabledIcons.splice( index, 1 ); }
  493. }
  494. }
  495. updateMapIcons();
  496. } );// non-blastable
  497. $( document ).on( 'change', '#check_poi', function( e ) {
  498. toggleAction( e.target );
  499. for ( var intCurr in arrPOI ) {
  500. var curr = arrPOI[ intCurr ];
  501. // console.log( '%d:%s: %o', intCurr, curr, arrBlastables );
  502.  
  503. if ( e.target.checked ) {
  504. // console.log( 'Hiding: %o', curr );
  505. $( '.v_poi.ico_show.haideris' ).removeClass( 'ico_show' ).addClass( 'ico_hide' );
  506. if ( disabledIcons.indexOf( curr ) == -1 ) { disabledIcons.push( curr ); }
  507. } else {
  508. // console.log( 'Showing: %o', curr );
  509. $( '.v_poi.ico_hide.haideris' ).removeClass( 'ico_hide' ).addClass( 'ico_show' );
  510. var index = disabledIcons.indexOf( curr );
  511. if ( index !== -1 ) { disabledIcons.splice( index, 1 ); }
  512. }
  513. }
  514. updateMapIcons();
  515. } );// POIs
  516. $( document ).on( 'change', '#be_reporter', function( e ) {
  517. isReporter = !isReporter;
  518. toggleAction( e.target, true );
  519. localStorage.setItem( 'MMF', JSON.stringify( { isReporter: isReporter, arrReported: arrReported } ) );
  520. } );// Be Reporter
  521. $( document ).ajaxSuccess( createfilter4Map );
  522. }
  523. else {
  524. log( 1, 'log', 'Detected page: %s', window.location.pathname );
  525. $( document ).on( 'mouseup', '#map_canvas', function( e ) { showAddress(); } );
  526. $( document ).on( 'click', '#map-box-specials-zoom-in', function( e ) { showAddress(); } );
  527. $( document ).on( 'click', '#map-box-specials-zoom-out', function( e ) { showAddress(); } );
  528. $( 'div#map_canvas' ).after( mapLocationSection );
  529. }