Zandboxee

Want better control of your Munzee sandbox? Here you go!

  1. // ==UserScript==
  2. // @name Zandboxee
  3. // @namespace none
  4. // @version 2020.04.21.0730
  5. // @description Want better control of your Munzee sandbox? Here you go!
  6. // @supportURL https://Discord.me/TheShoeStore
  7. // @author technical13
  8. // @match https://www.munzee.com/map/*
  9. // @grant none
  10. // ==/UserScript==
  11. // jshint esversion: 6
  12. /* KNOWN ISSUES LIST
  13. // Munzee's "Quick Deploy" feature may round the least significant digit of the latitude - not an issue with the script
  14. //*/
  15. /* TO-DO LIST
  16. // Add a way to import a .csv file into the sandbox
  17. // Add a way to import/export a sandbox as a .json file into/from the sandbox
  18. // Add a button to quick deploy each pin in the table - without using the actual (buggy) quick deploy function
  19. // Drag and drop reordering of pins
  20. //*/
  21.  
  22. var isDebug = false;
  23. var intVerbosity = 0;
  24. const ver = '2020.04.21.0730';
  25. const scriptName = 'Zandboxee v' + ver;
  26.  
  27. function log( intV, strConsole, strLog, ...arrArgs ) {
  28. if ( intV === undefined ) { intV = 0; }
  29. if ( strConsole === undefined ) { strConsole = 'log'; }
  30. if ( strLog === undefined ) { strLog = '%o'; }
  31. if ( intVerbosity >= intV && ( strConsole === 'groupEnd' ) ) { console[ strConsole ](); }
  32. if ( intV === 0 || ( isDebug && intVerbosity >= intV ) ) { console[ strConsole ]( '[%i]: %s: ' + strLog, intV, scriptName, ...arrArgs ); }
  33. }
  34.  
  35. function toBoolean( val ) {
  36. const arrTrue = [ undefined, null, '', true, 'true', 1, '1', 'on', 'yes' ];
  37. val = ( typeof( val ) === 'string' ? val.toLowerCase() : val );
  38.  
  39. log( 4, 'log', 'toBoolean() is returning: %o', ( arrTrue.indexOf( val ) !== -1 ? true : false ) );
  40. return ( arrTrue.indexOf( val ) !== -1 ? true : false );
  41. }
  42.  
  43. const intParamsStart = ( document.URL.indexOf( '?' ) + 1 );
  44. const strParams = document.URL.substr( intParamsStart );
  45. const arrParamSets = strParams.split( '&' );
  46. var objParams = {};
  47. arrParamSets.forEach( function( strParam ) {
  48. let arrParam = strParam.split( '=' );
  49. let strParamName = ( arrParam[ 0 ].toLowerCase() || '' );
  50. if ( strParamName === 'verbosity' ) {
  51. isDebug = true;
  52. intVerbosity = ( arrParam[ 1 ] ? ( parseInt( arrParam[ 1 ] ) < 0 ? 0 : ( parseInt( arrParam[ 1 ] ) > 9 ? 9 : parseInt( arrParam[ 1 ] ) ) ) : 9 );
  53. } else if ( strParamName === 'debug' ) {
  54. isDebug = toBoolean( arrParam[ 1 ] );
  55. intVerbosity = 1;
  56. } else if ( strParamName === 'sandbox' ) {
  57. objParams.doSandbox = toBoolean( arrParam[ 1 ] );
  58. } else if ( strParamName === 'lat' ) {
  59. objParams.lat = parseFloat( arrParam[ 1 ] );
  60. } else if ( strParamName === 'lon' ) {
  61. objParams.lon = parseFloat( arrParam[ 1 ] );
  62. } else if ( strParamName === 'name' ) {
  63. objParams.name = decodeURIComponent( arrParam[ 1 ] );
  64. } else if ( strParamName === 'issand' ) {
  65. objParams.isSandbox = toBoolean( arrParam[ 1 ] );
  66. }
  67. } );
  68. if ( objParams.doSandbox && objParams.lat && objParams.lon ) {
  69. objParams.geohash = window.geohash.encode( objParams.lat, objParams.lon, 9 );
  70. window.location = 'https://www.munzee.com/map/' + objParams.geohash + '/18?isSand=1&lat=' + objParams.lat + '&lon=' + objParams.lon + ( objParams.name ? '&name=' + objParams.name : '' );
  71. }
  72. log( 2, 'info', 'objParams: %o', objParams );
  73.  
  74. log( 1, 'warn', 'Debug mode is on with verbosity level: %o', intVerbosity );
  75. log( 1, 'groupCollapsed', 'Verbosity options: (click to expand)' );
  76. 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.' );
  77. log( 1, 'groupEnd' );
  78.  
  79. try {
  80. var munzeesandboxcounter = parseInt( localStorage.munzeesandboxcounter || 0 );
  81. var munzeesandbox = JSON.parse( localStorage.munzeesandbox || '[]' );
  82. if ( munzeesandboxcounter !== munzeesandbox.length ) {
  83. munzeesandboxcounter = munzeesandbox.length;
  84. localStorage.setItem( 'munzeesandboxcounter', munzeesandboxcounter );
  85. log( 1, 'error', 'munzeesandboxcounter failed sanity check!\n\tReset value to: %i', munzeesandboxcounter );
  86. }
  87. if ( munzeesandboxcounter > 0 ) {
  88. log( 3, 'log', 'Sandbox has %i pin%s in it.', munzeesandboxcounter, ( munzeesandboxcounter === 1 ? '' : 's' ) );
  89. } else {
  90. log( 3, 'error', 'Sandbox is empty.' );
  91. }
  92.  
  93. function mapChanged() {
  94. log( 4, 'log', 'mapChanged() updating Add new Munzee placeholder coordinates.' );
  95. document.getElementById( 'NewMunzeeLat' ).placeholder = window.map.getCenter().lat;
  96. document.getElementById( 'NewMunzeeLng' ).placeholder = window.map.getCenter().lng;
  97. }
  98. function pinMoved( objDragged ) {
  99. var intPin = 0;
  100. for ( var pinNode in window.mapSandbox.list ) { if ( objDragged.target._element.isSameNode( window.mapSandbox.list[ pinNode ].marker._element ) ) { intPin = parseInt( pinNode ); } }
  101.  
  102. var objUpdatedMunzee = {
  103. lng: objDragged.target._lngLat.lng,
  104. lat: objDragged.target._lngLat.lat
  105. };
  106.  
  107. log( 4, 'log', 'pinMoved( %i ) updating munzeesandbox with new coordinates: [ %o, %o ]', intPin, objUpdatedMunzee.lat, objUpdatedMunzee.lng );
  108. munzeesandbox[ intPin ][ 0 ] = objUpdatedMunzee.lat;
  109. munzeesandbox[ intPin ][ 1 ] = objUpdatedMunzee.lng;
  110.  
  111. log( 4, 'log', 'pinMoved( %i ) updating table row %i with new coordinates: [ %o, %o ]', intPin, ( intPin + 1 ), objUpdatedMunzee.lat, objUpdatedMunzee.lng );
  112. $( 'input#ZandboxRow-' + ( intPin + 1 ) + '-lat' )[ 0 ].value = objUpdatedMunzee.lat;
  113. $( 'input#ZandboxRow-' + ( intPin + 1 ) + '-lng' )[ 0 ].value = objUpdatedMunzee.lng;
  114.  
  115. log( 4, 'log', 'pinMoved() performing:\n\tFunction.saveSandbox()' );
  116. Function.saveSandbox();
  117. }
  118. Function.prototype.saveSandbox = function () {
  119. localStorage.setItem( 'munzeesandbox', JSON.stringify( munzeesandbox ) );
  120. localStorage.setItem( 'munzeesandboxcounter', munzeesandboxcounter );
  121. }
  122. function createTableHead() {
  123. var domZandboxTableHead = document.createElement( 'thead' );
  124. var domZandBoxTableHeadRow = document.createElement( 'tr' );
  125. var domZandBoxTableHeadColPin = document.createElement( 'th' );
  126. var domZandBoxTableHeadColLat = document.createElement( 'th' );
  127. var domZandBoxTableHeadColLon = document.createElement( 'th' );
  128. var domZandBoxTableHeadColOwn = document.createElement( 'th' );
  129. var domZandBoxTableHeadColName = document.createElement( 'th' );
  130. var domZandBoxTableHeadColId = document.createElement( 'th' );
  131. var domZandBoxTableHeadColSaveAddRem = document.createElement( 'th' );
  132.  
  133. domZandBoxTableHeadColId.className = 'hidden-id';
  134.  
  135. domZandBoxTableHeadColPin.style = 'text-align: center !important; width: 50px !important;';
  136. domZandBoxTableHeadColLat.style = 'text-align: center !important;';
  137. domZandBoxTableHeadColLon.style = 'text-align: center !important;';
  138. domZandBoxTableHeadColOwn.style = 'text-align: center !important;';
  139. domZandBoxTableHeadColName.style = 'text-align: center !important;';
  140. domZandBoxTableHeadColId.style = 'text-align: center !important; display: none;'
  141. domZandBoxTableHeadColSaveAddRem.style = 'text-align: center !important;';
  142.  
  143. domZandBoxTableHeadColPin.innerText = '#';
  144. domZandBoxTableHeadColLat.innerText = 'Latitude';
  145. domZandBoxTableHeadColLon.innerText = 'Longitude';
  146. domZandBoxTableHeadColOwn.innerText = 'Own';
  147. domZandBoxTableHeadColName.innerText = 'Name';
  148. domZandBoxTableHeadColId.innerText = 'ID';
  149. domZandBoxTableHeadColSaveAddRem.innerHTML = 'Save - Add/Remove';
  150.  
  151. domZandBoxTableHeadRow.append( domZandBoxTableHeadColPin );
  152. domZandBoxTableHeadRow.append( domZandBoxTableHeadColLat );
  153. domZandBoxTableHeadRow.append( domZandBoxTableHeadColLon );
  154. domZandBoxTableHeadRow.append( domZandBoxTableHeadColOwn );
  155. domZandBoxTableHeadRow.append( domZandBoxTableHeadColName );
  156. domZandBoxTableHeadRow.append( domZandBoxTableHeadColId );
  157. domZandBoxTableHeadRow.append( domZandBoxTableHeadColSaveAddRem );
  158.  
  159. domZandboxTableHead.append( domZandBoxTableHeadRow );
  160.  
  161. return domZandboxTableHead;
  162. }
  163. Function.prototype.removeTableRow = function ( valId ) {
  164. var intIndex = -1;
  165. if ( isNaN( valId ) ) {
  166. valId = valId.trim();
  167. intIndex = ( valId === 'ZandboxNewRow' ? ( $( 'table#ZandboxTable tr' ).length - 2 ) : parseInt( valId.replace( 'ZandboxRow-', '' ) ) )
  168. } else {
  169. intIndex = parseInt( valId );
  170. }
  171. log( 5, 'info', 'Function.prototype.removeTableRow() removing row %i-1 (from %o)', intIndex, valId );
  172. if ( valId !== 'ZandboxNewRow' ) {
  173. log( 4, 'log', 'Function.prototype.removeTableRow() updating row indices.' );
  174. $( 'table#ZandboxTable tr' ).each( function( intRow, domTR ) {
  175. if ( intRow === intIndex ) {
  176. log( 4, 'log', 'Function.prototype.removeTableRow() renaming row %i to ZandboxRemoveRow-%i', intRow, intRow );
  177. domTR.id = 'ZandboxRemoveRow-' + intRow;
  178. } else if ( intRow > intIndex && domTR.id !== 'ZandboxNewRow' ) {
  179. log( 4, 'log', 'Function.prototype.removeTableRow() calling Function.updateMunzee( %i )', ( intRow - 1 ) );
  180. Function.updateMunzee( intRow - 1 );
  181. log( 4, 'log', 'Function.prototype.removeTableRow() renumbering row %i to %i.', intRow, ( intRow - 1 ) );
  182. domTR.id = 'ZandboxRow-' + ( intRow - 1 );
  183. domTR.cells[ 0 ].innerText = ( intRow - 1 );
  184. domTR.cells[ 5 ].children[ 0 ].value = ( intRow - 1 );
  185. } else if ( domTR.id === 'ZandboxNewRow' ) {
  186. log( 4, 'log', 'Function.prototype.removeTableRow() renumbering add munzee row to %i.', ( intRow - 1 ) );
  187. domTR.cells[ 0 ].innerText = ( intRow - 1 );
  188. domTR.cells[ 5 ].children[ 0 ].placeholder = ( intRow - 2 );
  189. }
  190. } );
  191. } else {
  192. log( 4, 'log', 'Function.prototype.removeTableRow() renaming ZandboxNewRow to ZandboxRemoveRow.' );
  193. document.getElementById( 'ZandboxNewRow' ).id = 'ZandboxRemoveRow-' + intIndex;
  194. }
  195. log( 4, 'log', 'Function.prototype.removeTableRow() removing row %i (%o) from table.', intIndex, valId );
  196. $( 'tr#ZandboxRemoveRow-' + intIndex ).remove();
  197. }
  198. Function.prototype.createNewMunzeeRow = function () {
  199. log( 4, 'log', 'Function.prototype.createNewMunzeeRow() creating "Add new Munzee" row for table.' );
  200.  
  201. var domZandBoxTableRow = document.createElement( 'tr' );
  202. var domZandBoxTableRowPin = document.createElement( 'td' );
  203. var domZandBoxTableRowLat = document.createElement( 'td' );
  204. var domZandBoxTableRowLon = document.createElement( 'td' );
  205. var domZandBoxTableRowOwn = document.createElement( 'td' );
  206. var domZandBoxTableRowName = document.createElement( 'td' );
  207. var domZandBoxTableRowId = document.createElement( 'td' );
  208. var domZandBoxTableRowAddClear = document.createElement( 'td' );
  209.  
  210. domZandBoxTableRow.id = 'ZandboxNewRow';
  211. domZandBoxTableRowId.style = 'display: none;';
  212. domZandBoxTableRowId.className = 'hidden-id';
  213.  
  214. var domZandBoxTextPin = document.createTextNode( munzeesandbox.length + 1 );
  215. var domZandBoxInputLat = document.createElement( 'input' );
  216. var domZandBoxInputLon = document.createElement( 'input' );
  217. var domZandBoxInputOwn = document.createElement( 'input' );
  218. var domZandBoxInputName = document.createElement( 'input' );
  219. var domZandBoxInputId = document.createElement( 'input' );
  220. var domZandBoxInputAdd = document.createElement( 'input' );
  221. var domZandBoxInputClear = document.createElement( 'input' );
  222.  
  223. domZandBoxInputLat.type = 'text';
  224. domZandBoxInputLon.type = 'text';
  225. domZandBoxInputOwn.type = 'checkbox';
  226. domZandBoxInputName.type = 'text';
  227. domZandBoxInputId.type = 'number';
  228. domZandBoxInputAdd.type = 'button';
  229. domZandBoxInputClear.type = 'button';
  230.  
  231. domZandBoxInputLat.id = 'NewMunzeeLat';
  232. domZandBoxInputLon.id = 'NewMunzeeLng';
  233. domZandBoxInputOwn.id = 'NewMunzeeOwn';
  234. domZandBoxInputName.id = 'NewMunzeeName';
  235. domZandBoxInputId.id = 'NewMunzeeId';
  236. domZandBoxInputAdd.id = 'NewMunzeeAdd';
  237. domZandBoxInputClear.id = 'clearSB';
  238.  
  239. domZandBoxInputLat.size = '25';
  240. domZandBoxInputLon.size = '25';
  241. domZandBoxInputName.maxlength = '33';
  242. domZandBoxInputName.size = '35';
  243.  
  244. domZandBoxInputLat.style = 'text-align: right;';
  245. domZandBoxInputLon.style = 'text-align: right;';
  246. domZandBoxInputName.style = 'text-align: right;';
  247. domZandBoxInputId.style = 'text-align: center;';
  248. domZandBoxInputClear.style = 'background-color: #FF6666; font-weight: bold;';
  249.  
  250. domZandBoxInputLat.placeholder = window.map.getCenter().lat;
  251. domZandBoxInputLon.placeholder = window.map.getCenter().lng;
  252. domZandBoxInputOwn.checked = true;
  253. domZandBoxInputName.placeholder = 'Quick Deploy by ' + window.username;
  254. domZandBoxInputId.placeholder = munzeesandbox.length.toString();
  255. domZandBoxInputAdd.value = 'Add';
  256. domZandBoxInputAdd.setAttribute( 'onClick', 'Function.addMunzee();');
  257. domZandBoxInputClear.setAttribute( 'onClick', "if(confirm('Click OK if you are sure you want to clear your sandbox:',false)){Function.clearSandbox();}" );
  258. domZandBoxInputClear.value = 'Clear';
  259.  
  260. domZandBoxTableRowPin.append( domZandBoxTextPin );
  261. domZandBoxTableRowLat.append( domZandBoxInputLat );
  262. domZandBoxTableRowLon.append( domZandBoxInputLon );
  263. domZandBoxTableRowOwn.append( domZandBoxInputOwn );
  264. domZandBoxTableRowName.append( domZandBoxInputName );
  265. domZandBoxTableRowId.append( domZandBoxInputId );
  266. domZandBoxTableRowAddClear.append( domZandBoxInputAdd );
  267. domZandBoxTableRowAddClear.append( domZandBoxInputClear );
  268.  
  269. domZandBoxTableRow.append( domZandBoxTableRowPin );
  270. domZandBoxTableRow.append( domZandBoxTableRowLat );
  271. domZandBoxTableRow.append( domZandBoxTableRowLon );
  272. domZandBoxTableRow.append( domZandBoxTableRowOwn );
  273. domZandBoxTableRow.append( domZandBoxTableRowName );
  274. domZandBoxTableRow.append( domZandBoxTableRowId );
  275. domZandBoxTableRow.append( domZandBoxTableRowAddClear );
  276.  
  277. log( 4, 'log', 'Function.prototype.createNewMunzeeRow() returning new row DOM:\n\t%o', domZandBoxTableRow );
  278. return domZandBoxTableRow;
  279. }
  280. Function.prototype.addTableRow = function ( arrSandPin, intIndex ) {
  281. log( 4, 'log', 'Function.prototype.addTableRow() creating row #%i for table with pin:\n\t%o', ( intIndex + 1 ), arrSandPin );
  282.  
  283. var domZandBoxTableRow = document.createElement( 'tr' );
  284. var domZandBoxTableRowPin = document.createElement( 'td' );
  285. var domZandBoxTableRowLat = document.createElement( 'td' );
  286. var domZandBoxTableRowLon = document.createElement( 'td' );
  287. var domZandBoxTableRowOwn = document.createElement( 'td' );
  288. var domZandBoxTableRowName = document.createElement( 'td' );
  289. var domZandBoxTableRowId = document.createElement( 'td' );
  290. var domZandBoxTableRowSaveRemove = document.createElement( 'td' );
  291.  
  292. domZandBoxTableRow.id = 'ZandboxRow-' + ( intIndex + 1 );
  293. domZandBoxTableRowId.style = 'display: none;';
  294. domZandBoxTableRowId.className = 'hidden-id';
  295.  
  296. var domZandBoxTextPin = document.createTextNode( intIndex + 1 );
  297. var domZandBoxInputLat = document.createElement( 'input' );
  298. var domZandBoxInputLon = document.createElement( 'input' );
  299. var domZandBoxInputOwn = document.createElement( 'input' );
  300. var domZandBoxInputName = document.createElement( 'input' );
  301. var domZandBoxInputId = document.createElement( 'input' );
  302. var domZandBoxInputSave = document.createElement( 'input' );
  303. var domZandBoxInputRemove = document.createElement( 'input' );
  304.  
  305. domZandBoxInputLat.type = 'text';
  306. domZandBoxInputLon.type = 'text';
  307. domZandBoxInputOwn.type = 'checkbox';
  308. domZandBoxInputName.type = 'text';
  309. domZandBoxInputId.type = 'number';
  310. domZandBoxInputSave.type = 'button';
  311. domZandBoxInputRemove.type = 'button';
  312.  
  313. domZandBoxInputLat.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-lat';
  314. domZandBoxInputLon.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-lng';
  315. domZandBoxInputOwn.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-own';
  316. domZandBoxInputName.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-name';
  317. domZandBoxInputId.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-id';
  318.  
  319. domZandBoxInputLat.size = '25';
  320. domZandBoxInputLon.size = '25';
  321. domZandBoxInputName.maxlength = '33';
  322. domZandBoxInputName.size = '35';
  323.  
  324. domZandBoxInputLat.style = 'text-align: right;';
  325. domZandBoxInputLon.style = 'text-align: right;';
  326. domZandBoxInputName.style = 'text-align: right;';
  327. domZandBoxInputId.style = 'text-align: center;';
  328.  
  329. domZandBoxInputLat.setAttribute( 'value', ( arrSandPin[ 0 ] || 0 ) );
  330. domZandBoxInputLon.setAttribute( 'value', ( arrSandPin[ 1 ] || 0 ) );
  331. domZandBoxInputOwn.checked = ( arrSandPin[ 2 ] === 1 ? true : false );
  332. domZandBoxInputName.setAttribute( 'value', ( arrSandPin[ 3 ] || '' ) );
  333. domZandBoxInputId.setAttribute( 'value', ( arrSandPin[ 4 ] || '' ) );
  334. domZandBoxInputSave.setAttribute( 'value', 'Save' );
  335. domZandBoxInputSave.setAttribute( 'onClick', "Function.updateMunzee( parseInt( $( this ).parents( 'tr' ).attr( 'id' ).replace( 'ZandboxRow-', '' ) ) );" );
  336. domZandBoxInputRemove.setAttribute( 'value', 'Remove' );
  337. domZandBoxInputRemove.setAttribute( 'onClick', "Function.removeMunzee( parseInt( $( this ).parents( 'tr' ).attr( 'id' ).replace( 'ZandboxRow-', '' ) ) );" );
  338.  
  339. domZandBoxTableRowPin.append( domZandBoxTextPin );
  340. domZandBoxTableRowLat.append( domZandBoxInputLat );
  341. domZandBoxTableRowLon.append( domZandBoxInputLon );
  342. domZandBoxTableRowOwn.append( domZandBoxInputOwn );
  343. domZandBoxTableRowName.append( domZandBoxInputName );
  344. domZandBoxTableRowId.append( domZandBoxInputId );
  345. domZandBoxTableRowSaveRemove.append( domZandBoxInputSave );
  346. domZandBoxTableRowSaveRemove.append( domZandBoxInputRemove );
  347.  
  348. domZandBoxTableRow.append( domZandBoxTableRowPin );
  349. domZandBoxTableRow.append( domZandBoxTableRowLat );
  350. domZandBoxTableRow.append( domZandBoxTableRowLon );
  351. domZandBoxTableRow.append( domZandBoxTableRowOwn );
  352. domZandBoxTableRow.append( domZandBoxTableRowName );
  353. domZandBoxTableRow.append( domZandBoxTableRowId );
  354. domZandBoxTableRow.append( domZandBoxTableRowSaveRemove );
  355.  
  356. log( 4, 'log', 'Function.prototype.addTableRow() returning new row DOM:\n\t%o', domZandBoxTableRow );
  357. return domZandBoxTableRow;
  358. }
  359. Function.prototype.updateMunzee = function( valId ) {
  360. var intIndex = ( isNaN( valId ) ? parseInt( valId.replace( 'ZandboxRow-', '' ) ) : valId );
  361. log( 5, 'info', 'Function.prototype.updateMunzee() updating sandbox item %i-1 (from %o)', intIndex, valId );
  362. log( 4, 'log', 'Function.prototype.updateMunzee() updating munzee %s', munzeesandbox[ intIndex - 1 ][ 3 ] );
  363.  
  364. var objUpdatedMunzee = {
  365. lng: parseFloat( $( 'input#ZandboxRow-' + intIndex + '-lng' ).val() || window.map.getCenter().lng ),
  366. lat: parseFloat( $( 'input#ZandboxRow-' + intIndex + '-lat' ).val() || window.map.getCenter().lat ),
  367. name: ( $( 'input#ZandboxRow-' + intIndex + '-name' ).val() || 'Quick Deploy by " + username + "' ),
  368. id: ( $( 'input#ZandboxRow-' + intIndex + '-id' ).val() || ( intIndex - 1 ).toString() ),
  369. own: ( document.getElementById( 'ZandboxRow-' + intIndex + '-own' ).checked ? 1 : 0 )
  370. };
  371.  
  372. log( 4, 'log', 'Function.prototype.updateMunzee() updating marker on map from [ %o, %o ] to [ %o, %o ]',
  373. window.mapSandbox.list[ ( intIndex - 1 ) ].marker._lngLat.lng, window.mapSandbox.list[ ( intIndex - 1 ) ].marker._lngLat.lat, objUpdatedMunzee.lng, objUpdatedMunzee.lat
  374. );
  375. window.mapSandbox.list[ ( intIndex - 1 ) ].marker.setLngLat( [ objUpdatedMunzee.lng, objUpdatedMunzee.lat ] );
  376.  
  377. log( 4, 'log', 'Function.prototype.updateMunzee() updating mapSandbox.list[ %i ] (%s)', ( intIndex - 1 ), window.mapSandbox.list[ intIndex - 1 ].title );
  378. window.mapSandbox.list[ intIndex - 1 ].id = objUpdatedMunzee.id;
  379. window.mapSandbox.list[ intIndex - 1 ].title = objUpdatedMunzee.name;
  380. window.mapSandbox.list[ intIndex - 1 ].coordinates[ 0 ] = objUpdatedMunzee.lng;
  381. window.mapSandbox.list[ intIndex - 1 ].coordinates[ 1 ] = objUpdatedMunzee.lat;
  382. window.mapSandbox.list[ intIndex - 1 ].myOwn = objUpdatedMunzee.own;
  383. log( 4, 'info', 'Function.prototype.updateMunzee() updated %i in mapSandbox.list to:\n\t%o', ( intIndex - 1 ), window.mapSandbox.list[ intIndex - 1 ] );
  384.  
  385. log( 4, 'log', 'Function.prototype.updateMunzee() performing:\n\tmunzeesandbox[ %i ] = %o', ( intIndex - 1 ), [ objUpdatedMunzee.lng, objUpdatedMunzee.lat, objUpdatedMunzee.own, objUpdatedMunzee.name, objUpdatedMunzee.id ] );
  386. munzeesandbox[ intIndex - 1 ] = [ objUpdatedMunzee.lat, objUpdatedMunzee.lng, objUpdatedMunzee.own, objUpdatedMunzee.name, objUpdatedMunzee.id ];
  387.  
  388. log( 4, 'log', 'Function.prototype.updateMunzee() performing:\n\tFunction.saveSandbox()' );
  389. Function.saveSandbox();
  390. }
  391. Function.prototype.removeMunzee = function ( valId ) {
  392. var intIndex = ( isNaN( valId ) ? parseInt( valId.replace( 'ZandboxRow-', '' ) ) : valId );
  393. log( 4, 'log', 'Function.prototype.removeMunzee() removing munzee (%o) %i (%s) from sandbox.', valId, ( intIndex - 1 ), munzeesandbox[ intIndex - 1 ][ 3 ] );
  394.  
  395. log( 4, 'log', 'Function.prototype.removeMunzee() removing marker from map' );
  396. window.mapSandbox.list[ ( intIndex - 1 ) ].marker.remove();
  397.  
  398. log( 4, 'log', 'Function.prototype.removeMunzee() splicing %i (%s) from mapSandbox.list', ( intIndex - 1 ), window.mapSandbox.list[ intIndex - 1 ].title );
  399. window.mapSandbox.list.splice( ( intIndex - 1 ), 1 );
  400. log( 4, 'info', 'Function.prototype.removeMunzee() spliced %i from mapSandbox.list leaving:\n\t%o', ( intIndex - 1 ), window.mapSandbox.list );
  401.  
  402. log( 4, 'log', 'Function.prototype.removeMunzee() splicing %i (%s) from munzeesandbox', ( intIndex - 1 ), munzeesandbox[ intIndex - 1 ][ 3 ] );
  403. munzeesandbox.splice( ( intIndex - 1 ), 1 );
  404. log( 4, 'info', 'Function.prototype.removeMunzee() spliced %i from munzeesandbox leaving:\n\t%o', ( intIndex - 1 ), munzeesandbox );
  405.  
  406. log( 4, 'info', 'Function.prototype.removeMunzee() decrementing munzeesandboxcounter-- to %i', ( munzeesandboxcounter - 1 ) );
  407. munzeesandboxcounter--;
  408.  
  409. log( 4, 'log', 'Function.prototype.removeMunzee() performing:\n\tFunction.saveSandbox()' );
  410. Function.saveSandbox();
  411.  
  412. log( 4, 'log', 'Function.prototype.removeMunzee() performing:\n\tFunction.removeTableRow( %o )', intIndex );
  413. Function.removeTableRow( intIndex );
  414. }
  415. Function.prototype.addMunzee = function() {
  416. var objNewMunzee = {
  417. lng: ( $( 'input#NewMunzeeLng' ).val() || window.map.getCenter().lng ),
  418. lat: ( $( 'input#NewMunzeeLat' ).val() || window.map.getCenter().lat ),
  419. name: ( $( 'input#NewMunzeeName' ).val() || 'Quick Deploy by ' + window.username ),
  420. id: ( $( 'input#NewMunzeeId' ).val() || $( 'input#NewMunzeeId' )[ 0 ].placeholder ),
  421. own: ( document.getElementById( 'NewMunzeeOwn' ).checked ? 1 : 0 )
  422. };
  423.  
  424. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tmapSandbox.addItem( %o, %o, %o )', [ objNewMunzee.lng, objNewMunzee.lat ], objNewMunzee.name, objNewMunzee.own );
  425. window.mapSandbox.addItem( [ objNewMunzee.lng, objNewMunzee.lat ], objNewMunzee.name, objNewMunzee.own );
  426. window.mapSandbox.list[ window.mapSandbox.length - 1 ].marker.on( 'dragend', objDragged => pinMoved( objDragged ) );
  427. log( 2, 'log', 'Created move listener for pin #%i', ( window.mapSandbox.length - 1 ) );
  428. window.initilSB = 1;
  429.  
  430. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tmunzeesandbox.push( %o )', [ objNewMunzee.lat, objNewMunzee.lng, objNewMunzee.own, objNewMunzee.name, munzeesandboxcounter.toString() ] );
  431. munzeesandbox.push( [ objNewMunzee.lat, objNewMunzee.lng, objNewMunzee.own, objNewMunzee.name, munzeesandboxcounter.toString() ] );
  432. munzeesandboxcounter++;
  433. log( 4, 'info', 'munzeesandbox now contains:\n%o', munzeesandbox );
  434.  
  435. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.removeTableRow( \'%s\' )', 'ZandboxNewRow' );
  436. Function.removeTableRow( 'ZandboxNewRow' );
  437.  
  438. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.addTableRow( %o, %i )', munzeesandbox[ munzeesandboxcounter - 1 ], munzeesandboxcounter - 1 );
  439. $( 'table#ZandboxTable > tbody' ).append( Function.addTableRow( munzeesandbox[ munzeesandboxcounter - 1 ], munzeesandboxcounter - 1 ) );
  440.  
  441. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.createNewMunzeeRow()' );
  442. $( 'table#ZandboxTable > tbody' ).append( Function.createNewMunzeeRow() );
  443.  
  444. if ( isDebug ) {
  445. $( '.hidden-id' ).show();
  446. }
  447. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.saveSandbox()' );
  448. Function.saveSandbox();
  449. }
  450. Function.prototype.clearSandbox = function() {
  451. log( 4, 'log', 'Function.prototype.clearSandbox clearing localStorage items.' );
  452. localStorage.removeItem( 'munzeesandboxcounter' );
  453. localStorage.removeItem( 'munzeesandbox' );
  454.  
  455. log( 4, 'log', 'Function.prototype.clearSandbox performing:\n\t$( \'tr#ZandboxNewRow\' ).remove()' );
  456. $( 'tr#ZandboxNewRow' ).remove();
  457.  
  458. log( 4, 'log', 'Function.prototype.clearSandbox clearing table rows.' );
  459. for ( var i = $( 'table#ZandboxTable > tbody > tr' ).length; i > 0; i-- ) {
  460. log( 4, 'log', 'Function.prototype.clearSandbox performing:\n\t$( \'tr#ZandboxRow-\' + %i ).remove()', i );
  461. $( 'tr#ZandboxRow-' + i ).remove();
  462. log( 4, 'log', 'Function.prototype.removeMunzee() removing marker from map' );
  463. window.mapSandbox.list[ i - 1 ].marker.remove();
  464. }
  465.  
  466. log( 4, 'log', 'Function.prototype.clearSandbox performing Function.createNewMunzeeRow()' );
  467. $( 'table#ZandboxTable > tbody' ).append( Function.createNewMunzeeRow() );
  468. }
  469.  
  470. function showSandbox() {
  471. $( 'div#showsandbox' ).empty();// hide button
  472. window.mapSandbox = window.initSandbox();// initialize sandbox
  473. var arrSandBoxMunzee = JSON.parse( localStorage.getItem( 'munzeesandbox' ) );
  474.  
  475. // Create move listeners for all existing sandbox pins to update coords with move
  476. for ( var n in arrSandBoxMunzee ) {
  477. window.mapSandbox.addItem( [ arrSandBoxMunzee[ n ][ 1 ], arrSandBoxMunzee[ n ][ 0 ] ], arrSandBoxMunzee[ n ][ 3 ], arrSandBoxMunzee[ n ][ 2 ] );
  478. window.mapSandbox.list[ n ].marker.on( 'dragend', objDragged => pinMoved( objDragged ) );
  479. log( 2, 'log', 'Created move listener for pin #%i', n );
  480. }
  481. $( 'div.panel.panel-default' ).append( domZandboxDiv );// Add table with contents of sandbox
  482.  
  483. if ( isDebug ) {
  484. //Show the hidden column for debugging purposes
  485. $( '.hidden-id' ).show();
  486. }
  487.  
  488. window.scrollByLines( 10 );// Scroll down a little so people can see the table
  489.  
  490. //Update currently location to add a new pin if the map is changed at all
  491. window.map.on( 'resize', mapChanged ).on( 'touchend', mapChanged ).on( 'dragend', mapChanged ).on( 'zoomend', mapChanged ).on( 'moveend', mapChanged );
  492. }
  493.  
  494. var domZandboxDiv = document.createElement( 'div' );
  495. domZandboxDiv.id = 'zandbox';
  496. domZandboxDiv.className = 'panel-footer';
  497. domZandboxDiv.style = 'text-align: center;';
  498.  
  499. var domZandboxTable = document.createElement( 'table' );
  500. domZandboxTable.id = 'ZandboxTable';
  501. domZandboxTable.style = 'width: 100%;';
  502.  
  503. domZandboxTable.append( createTableHead() );
  504.  
  505. var domZandboxTableBody = document.createElement( 'tbody' );
  506.  
  507. munzeesandbox.forEach( function( arrSandPin, intIndex, arrSandbox ) {
  508. domZandboxTableBody.append( Function.addTableRow( arrSandPin, intIndex ) );
  509. } );
  510.  
  511. domZandboxTableBody.append( Function.createNewMunzeeRow() );
  512.  
  513. domZandboxTable.append( domZandboxTableBody );
  514. domZandboxDiv.append( domZandboxTable );
  515.  
  516. ( function() {
  517. 'use strict';
  518. log( 0, 'info', 'Script loaded.' );
  519.  
  520. $( 'div#filterboxes label' ).eq( 0 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 0 )[ 0 ].childNodes[ 2 ].nodeValue
  521. .replace( ' munzees', '' ).replace( 'exclude', 'hide' );// Shorten & clarify `exclude own munzees`
  522. $( 'div#filterboxes label' ).eq( 1 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 1 )[ 0 ].childNodes[ 2 ].nodeValue
  523. .replace( ' munzees', '' ).replace( 'exclude', 'hide' );// Shorten & clarify `exclude captured munzees`
  524. $( 'div#filterboxes label' ).eq( 4 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 4 )[ 0 ].childNodes[ 2 ].nodeValue
  525. .replace( 'only uncaptured', 'FTC opportunities' );// Clarify `only uncaptured`
  526. $( 'div#sandbox' ).remove();// We're not going to use the default sandbox buttons anymore.
  527.  
  528. $( 'input#showSBbuttons' ).click( function( event ) {
  529. event.preventDefault();
  530. showSandbox();
  531. } );
  532.  
  533. if ( objParams.isSandbox ) {
  534. $( 'input#check_circles' ).click();
  535. showSandbox();
  536. $( 'input#NewMunzeeLat' ).val( objParams.lat );
  537. $( 'input#NewMunzeeLng' ).val( objParams.lon );
  538. $( 'input#NewMunzeeOwn' ).prop( 'checked', false );
  539. $( 'input#NewMunzeeName' ).val( objParams.name );
  540. $( 'input#NewMunzeeAdd' ).click();
  541. }
  542. } )();
  543. } catch ( errZandbox ) {
  544. if ( window.location.pathname.split( '/' )[ 1 ] === 'map' ) { console.error( 'errZandbox: %o', errZandbox ); }
  545. }