Zandboxee

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

当前为 2019-01-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Zandboxee
  3. // @namespace none
  4. // @version 2019.01.08.1438ß
  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 = '2019.01.08.1438ß';
  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. }
  57. } );
  58.  
  59. log( 1, 'warn', 'Debug mode is on with verbosity level: %o', intVerbosity );
  60. log( 1, 'groupCollapsed', 'Verbosity options: (click to expand)' );
  61. 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.' );
  62. log( 1, 'groupEnd' );
  63.  
  64. var munzeesandboxcounter = parseInt( localStorage.munzeesandboxcounter || 0 );
  65. var munzeesandbox = JSON.parse( localStorage.munzeesandbox || '[]' );
  66. if ( munzeesandboxcounter !== munzeesandbox.length ) {
  67. munzeesandboxcounter = munzeesandbox.length;
  68. localStorage.setItem( 'munzeesandboxcounter', munzeesandboxcounter );
  69. log( 1, 'error', 'munzeesandboxcounter failed sanity check!\n\tReset value to: %i', munzeesandboxcounter );
  70. }
  71. if ( munzeesandboxcounter > 0 ) {
  72. log( 3, 'log', 'Sandbox has %i pin%s in it.', munzeesandboxcounter, ( munzeesandboxcounter === 1 ? '' : 's' ) );
  73. } else {
  74. log( 3, 'error', 'Sandbox is empty.' );
  75. }
  76.  
  77. function mapChanged() {
  78. log( 4, 'log', 'mapChanged() updating Add new Munzee placeholder coordinates.' );
  79. document.getElementById( 'NewMunzeeLat' ).placeholder = map.getCenter().lat;
  80. document.getElementById( 'NewMunzeeLng' ).placeholder = map.getCenter().lng;
  81. }
  82. function pinMoved( objDragged ) {
  83. var intPin = 0;
  84. for ( var pinNode in mapSandbox.list ) { if ( objDragged.target._element.isSameNode( mapSandbox.list[ pinNode ].marker._element ) ) { intPin = parseInt( pinNode ); } }
  85.  
  86. var objUpdatedMunzee = {
  87. lng: objDragged.target._lngLat.lng,
  88. lat: objDragged.target._lngLat.lat
  89. };
  90.  
  91. log( 4, 'log', 'pinMoved( %i ) updating munzeesandbox with new coordinates: [ %o, %o ]', intPin, objUpdatedMunzee.lat, objUpdatedMunzee.lng );
  92. munzeesandbox[ intPin ][ 0 ] = objUpdatedMunzee.lat;
  93. munzeesandbox[ intPin ][ 1 ] = objUpdatedMunzee.lng;
  94.  
  95. log( 4, 'log', 'pinMoved( %i ) updating table row %i with new coordinates: [ %o, %o ]', intPin, ( intPin + 1 ), objUpdatedMunzee.lat, objUpdatedMunzee.lng );
  96. $( 'input#ZandboxRow-' + ( intPin + 1 ) + '-lat' )[ 0 ].value = objUpdatedMunzee.lat;
  97. $( 'input#ZandboxRow-' + ( intPin + 1 ) + '-lng' )[ 0 ].value = objUpdatedMunzee.lng;
  98.  
  99. log( 4, 'log', 'pinMoved() performing:\n\tFunction.saveSandbox()' );
  100. Function.saveSandbox();
  101. }
  102. Function.prototype.saveSandbox = function () {
  103. localStorage.setItem( 'munzeesandbox', JSON.stringify( munzeesandbox ) );
  104. localStorage.setItem( 'munzeesandboxcounter', munzeesandboxcounter );
  105. }
  106. function createTableHead() {
  107. var domZandboxTableHead = document.createElement( 'thead' );
  108. var domZandBoxTableHeadRow = document.createElement( 'tr' );
  109. var domZandBoxTableHeadColPin = document.createElement( 'th' );
  110. var domZandBoxTableHeadColLat = document.createElement( 'th' );
  111. var domZandBoxTableHeadColLon = document.createElement( 'th' );
  112. var domZandBoxTableHeadColOwn = document.createElement( 'th' );
  113. var domZandBoxTableHeadColName = document.createElement( 'th' );
  114. var domZandBoxTableHeadColId = document.createElement( 'th' );
  115. var domZandBoxTableHeadColSaveAddRem = document.createElement( 'th' );
  116.  
  117. domZandBoxTableHeadColId.className = 'hidden-id';
  118.  
  119. domZandBoxTableHeadColPin.style = 'text-align: center !important; width: 50px !important;';
  120. domZandBoxTableHeadColLat.style = 'text-align: center !important;';
  121. domZandBoxTableHeadColLon.style = 'text-align: center !important;';
  122. domZandBoxTableHeadColOwn.style = 'text-align: center !important;';
  123. domZandBoxTableHeadColName.style = 'text-align: center !important;';
  124. domZandBoxTableHeadColId.style = 'text-align: center !important; display: none;'
  125. domZandBoxTableHeadColSaveAddRem.style = 'text-align: center !important;';
  126.  
  127. domZandBoxTableHeadColPin.innerText = '#';
  128. domZandBoxTableHeadColLat.innerText = 'Latitude';
  129. domZandBoxTableHeadColLon.innerText = 'Longitude';
  130. domZandBoxTableHeadColOwn.innerText = 'Own';
  131. domZandBoxTableHeadColName.innerText = 'Name';
  132. domZandBoxTableHeadColId.innerText = 'ID';
  133. domZandBoxTableHeadColSaveAddRem.innerHTML = 'Save - Add/Remove';
  134.  
  135. domZandBoxTableHeadRow.append( domZandBoxTableHeadColPin );
  136. domZandBoxTableHeadRow.append( domZandBoxTableHeadColLat );
  137. domZandBoxTableHeadRow.append( domZandBoxTableHeadColLon );
  138. domZandBoxTableHeadRow.append( domZandBoxTableHeadColOwn );
  139. domZandBoxTableHeadRow.append( domZandBoxTableHeadColName );
  140. domZandBoxTableHeadRow.append( domZandBoxTableHeadColId );
  141. domZandBoxTableHeadRow.append( domZandBoxTableHeadColSaveAddRem );
  142.  
  143. domZandboxTableHead.append( domZandBoxTableHeadRow );
  144.  
  145. return domZandboxTableHead;
  146. }
  147. Function.prototype.removeTableRow = function ( valId ) {
  148. var intIndex = -1;
  149. if ( isNaN( valId ) ) {
  150. valId = valId.trim();
  151. intIndex = ( valId === 'ZandboxNewRow' ? ( $( 'table#ZandboxTable tr' ).length - 2 ) : parseInt( valId.replace( 'ZandboxRow-', '' ) ) )
  152. } else {
  153. intIndex = parseInt( valId );
  154. }
  155. log( 5, 'info', 'Function.prototype.removeTableRow() removing row %i-1 (from %o)', intIndex, valId );
  156. if ( valId !== 'ZandboxNewRow' ) {
  157. log( 4, 'log', 'Function.prototype.removeTableRow() updating row indices.' );
  158. $( 'table#ZandboxTable tr' ).each( function( intRow, domTR ) {
  159. if ( intRow === intIndex ) {
  160. log( 4, 'log', 'Function.prototype.removeTableRow() renaming row %i to ZandboxRemoveRow-%i', intRow, intRow );
  161. domTR.id = 'ZandboxRemoveRow-' + intRow;
  162. } else if ( intRow > intIndex && domTR.id !== 'ZandboxNewRow' ) {
  163. log( 4, 'log', 'Function.prototype.removeTableRow() calling Function.updateMunzee( %i )', ( intRow - 1 ) );
  164. Function.updateMunzee( intRow - 1 );
  165. log( 4, 'log', 'Function.prototype.removeTableRow() renumbering row %i to %i.', intRow, ( intRow - 1 ) );
  166. domTR.id = 'ZandboxRow-' + ( intRow - 1 );
  167. domTR.cells[ 0 ].innerText = ( intRow - 1 );
  168. domTR.cells[ 5 ].children[ 0 ].value = ( intRow - 1 );
  169. } else if ( domTR.id === 'ZandboxNewRow' ) {
  170. log( 4, 'log', 'Function.prototype.removeTableRow() renumbering add munzee row to %i.', ( intRow - 1 ) );
  171. domTR.cells[ 0 ].innerText = ( intRow - 1 );
  172. domTR.cells[ 5 ].children[ 0 ].placeholder = ( intRow - 2 );
  173. }
  174. } );
  175. } else {
  176. log( 4, 'log', 'Function.prototype.removeTableRow() renaming ZandboxNewRow to ZandboxRemoveRow.' );
  177. document.getElementById( 'ZandboxNewRow' ).id = 'ZandboxRemoveRow-' + intIndex;
  178. }
  179. log( 4, 'log', 'Function.prototype.removeTableRow() removing row %i (%o) from table.', intIndex, valId );
  180. $( 'tr#ZandboxRemoveRow-' + intIndex ).remove();
  181. }
  182. Function.prototype.createNewMunzeeRow = function () {
  183. log( 4, 'log', 'Function.prototype.createNewMunzeeRow() creating "Add new Munzee" row for table.' );
  184.  
  185. var domZandBoxTableRow = document.createElement( 'tr' );
  186. var domZandBoxTableRowPin = document.createElement( 'td' );
  187. var domZandBoxTableRowLat = document.createElement( 'td' );
  188. var domZandBoxTableRowLon = document.createElement( 'td' );
  189. var domZandBoxTableRowOwn = document.createElement( 'td' );
  190. var domZandBoxTableRowName = document.createElement( 'td' );
  191. var domZandBoxTableRowId = document.createElement( 'td' );
  192. var domZandBoxTableRowAddClear = document.createElement( 'td' );
  193.  
  194. domZandBoxTableRow.id = 'ZandboxNewRow';
  195. domZandBoxTableRowId.style = 'display: none;';
  196. domZandBoxTableRowId.className = 'hidden-id';
  197.  
  198. var domZandBoxTextPin = document.createTextNode( munzeesandbox.length + 1 );
  199. var domZandBoxInputLat = document.createElement( 'input' );
  200. var domZandBoxInputLon = document.createElement( 'input' );
  201. var domZandBoxInputOwn = document.createElement( 'input' );
  202. var domZandBoxInputName = document.createElement( 'input' );
  203. var domZandBoxInputId = document.createElement( 'input' );
  204. var domZandBoxInputAdd = document.createElement( 'input' );
  205. var domZandBoxInputClear = document.createElement( 'input' );
  206.  
  207. domZandBoxInputLat.type = 'text';
  208. domZandBoxInputLon.type = 'text';
  209. domZandBoxInputOwn.type = 'checkbox';
  210. domZandBoxInputName.type = 'text';
  211. domZandBoxInputId.type = 'number';
  212. domZandBoxInputAdd.type = 'button';
  213. domZandBoxInputClear.type = 'button';
  214.  
  215. domZandBoxInputLat.id = 'NewMunzeeLat';
  216. domZandBoxInputLon.id = 'NewMunzeeLng';
  217. domZandBoxInputOwn.id = 'NewMunzeeOwn';
  218. domZandBoxInputName.id = 'NewMunzeeName';
  219. domZandBoxInputId.id = 'NewMunzeeId';
  220. domZandBoxInputAdd.id = 'NewMunzeeAdd';
  221. domZandBoxInputClear.id = 'clearSB';
  222.  
  223. domZandBoxInputLat.size = '25';
  224. domZandBoxInputLon.size = '25';
  225. domZandBoxInputName.maxlength = '33';
  226. domZandBoxInputName.size = '35';
  227.  
  228. domZandBoxInputLat.style = 'text-align: right;';
  229. domZandBoxInputLon.style = 'text-align: right;';
  230. domZandBoxInputName.style = 'text-align: right;';
  231. domZandBoxInputId.style = 'text-align: center;';
  232. domZandBoxInputClear.style = 'background-color: #FF6666; font-weight: bold;';
  233.  
  234. domZandBoxInputLat.placeholder = map.getCenter().lat;
  235. domZandBoxInputLon.placeholder = map.getCenter().lng;
  236. domZandBoxInputOwn.checked = true;
  237. domZandBoxInputName.placeholder = 'Quick Deploy by ' + username;
  238. domZandBoxInputId.placeholder = munzeesandbox.length.toString();
  239. domZandBoxInputAdd.value = 'Add';
  240. domZandBoxInputAdd.setAttribute( 'onClick', 'Function.addMunzee();');
  241. domZandBoxInputClear.setAttribute( 'onClick', "if(confirm('Click OK if you are sure you want to clear your sandbox:',false)){Function.clearSandbox();}" );
  242. domZandBoxInputClear.value = 'Clear';
  243.  
  244. domZandBoxTableRowPin.append( domZandBoxTextPin );
  245. domZandBoxTableRowLat.append( domZandBoxInputLat );
  246. domZandBoxTableRowLon.append( domZandBoxInputLon );
  247. domZandBoxTableRowOwn.append( domZandBoxInputOwn );
  248. domZandBoxTableRowName.append( domZandBoxInputName );
  249. domZandBoxTableRowId.append( domZandBoxInputId );
  250. domZandBoxTableRowAddClear.append( domZandBoxInputAdd );
  251. domZandBoxTableRowAddClear.append( domZandBoxInputClear );
  252.  
  253. domZandBoxTableRow.append( domZandBoxTableRowPin );
  254. domZandBoxTableRow.append( domZandBoxTableRowLat );
  255. domZandBoxTableRow.append( domZandBoxTableRowLon );
  256. domZandBoxTableRow.append( domZandBoxTableRowOwn );
  257. domZandBoxTableRow.append( domZandBoxTableRowName );
  258. domZandBoxTableRow.append( domZandBoxTableRowId );
  259. domZandBoxTableRow.append( domZandBoxTableRowAddClear );
  260.  
  261. log( 4, 'log', 'Function.prototype.createNewMunzeeRow() returning new row DOM:\n\t%o', domZandBoxTableRow );
  262. return domZandBoxTableRow;
  263. }
  264. Function.prototype.addTableRow = function ( arrSandPin, intIndex ) {
  265. log( 4, 'log', 'Function.prototype.addTableRow() creating row #%i for table with pin:\n\t%o', ( intIndex + 1 ), arrSandPin );
  266.  
  267. var domZandBoxTableRow = document.createElement( 'tr' );
  268. var domZandBoxTableRowPin = document.createElement( 'td' );
  269. var domZandBoxTableRowLat = document.createElement( 'td' );
  270. var domZandBoxTableRowLon = document.createElement( 'td' );
  271. var domZandBoxTableRowOwn = document.createElement( 'td' );
  272. var domZandBoxTableRowName = document.createElement( 'td' );
  273. var domZandBoxTableRowId = document.createElement( 'td' );
  274. var domZandBoxTableRowSaveRemove = document.createElement( 'td' );
  275.  
  276. domZandBoxTableRow.id = 'ZandboxRow-' + ( intIndex + 1 );
  277. domZandBoxTableRowId.style = 'display: none;';
  278. domZandBoxTableRowId.className = 'hidden-id';
  279.  
  280. var domZandBoxTextPin = document.createTextNode( intIndex + 1 );
  281. var domZandBoxInputLat = document.createElement( 'input' );
  282. var domZandBoxInputLon = document.createElement( 'input' );
  283. var domZandBoxInputOwn = document.createElement( 'input' );
  284. var domZandBoxInputName = document.createElement( 'input' );
  285. var domZandBoxInputId = document.createElement( 'input' );
  286. var domZandBoxInputSave = document.createElement( 'input' );
  287. var domZandBoxInputRemove = document.createElement( 'input' );
  288.  
  289. domZandBoxInputLat.type = 'text';
  290. domZandBoxInputLon.type = 'text';
  291. domZandBoxInputOwn.type = 'checkbox';
  292. domZandBoxInputName.type = 'text';
  293. domZandBoxInputId.type = 'number';
  294. domZandBoxInputSave.type = 'button';
  295. domZandBoxInputRemove.type = 'button';
  296.  
  297. domZandBoxInputLat.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-lat';
  298. domZandBoxInputLon.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-lng';
  299. domZandBoxInputOwn.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-own';
  300. domZandBoxInputName.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-name';
  301. domZandBoxInputId.id = 'ZandboxRow-' + ( intIndex + 1 ) + '-id';
  302.  
  303. domZandBoxInputLat.size = '25';
  304. domZandBoxInputLon.size = '25';
  305. domZandBoxInputName.maxlength = '33';
  306. domZandBoxInputName.size = '35';
  307.  
  308. domZandBoxInputLat.style = 'text-align: right;';
  309. domZandBoxInputLon.style = 'text-align: right;';
  310. domZandBoxInputName.style = 'text-align: right;';
  311. domZandBoxInputId.style = 'text-align: center;';
  312.  
  313. domZandBoxInputLat.setAttribute( 'value', ( arrSandPin[ 0 ] || 0 ) );
  314. domZandBoxInputLon.setAttribute( 'value', ( arrSandPin[ 1 ] || 0 ) );
  315. domZandBoxInputOwn.checked = ( arrSandPin[ 2 ] === 1 ? true : false );
  316. domZandBoxInputName.setAttribute( 'value', ( arrSandPin[ 3 ] || '' ) );
  317. domZandBoxInputId.setAttribute( 'value', ( arrSandPin[ 4 ] || '' ) );
  318. domZandBoxInputSave.setAttribute( 'value', 'Save' );
  319. domZandBoxInputSave.setAttribute( 'onClick', "Function.updateMunzee( parseInt( $( this ).parents( 'tr' ).attr( 'id' ).replace( 'ZandboxRow-', '' ) ) );" );
  320. domZandBoxInputRemove.setAttribute( 'value', 'Remove' );
  321. domZandBoxInputRemove.setAttribute( 'onClick', "Function.removeMunzee( parseInt( $( this ).parents( 'tr' ).attr( 'id' ).replace( 'ZandboxRow-', '' ) ) );" );
  322.  
  323. domZandBoxTableRowPin.append( domZandBoxTextPin );
  324. domZandBoxTableRowLat.append( domZandBoxInputLat );
  325. domZandBoxTableRowLon.append( domZandBoxInputLon );
  326. domZandBoxTableRowOwn.append( domZandBoxInputOwn );
  327. domZandBoxTableRowName.append( domZandBoxInputName );
  328. domZandBoxTableRowId.append( domZandBoxInputId );
  329. domZandBoxTableRowSaveRemove.append( domZandBoxInputSave );
  330. domZandBoxTableRowSaveRemove.append( domZandBoxInputRemove );
  331.  
  332. domZandBoxTableRow.append( domZandBoxTableRowPin );
  333. domZandBoxTableRow.append( domZandBoxTableRowLat );
  334. domZandBoxTableRow.append( domZandBoxTableRowLon );
  335. domZandBoxTableRow.append( domZandBoxTableRowOwn );
  336. domZandBoxTableRow.append( domZandBoxTableRowName );
  337. domZandBoxTableRow.append( domZandBoxTableRowId );
  338. domZandBoxTableRow.append( domZandBoxTableRowSaveRemove );
  339.  
  340. log( 4, 'log', 'Function.prototype.addTableRow() returning new row DOM:\n\t%o', domZandBoxTableRow );
  341. return domZandBoxTableRow;
  342. }
  343. Function.prototype.updateMunzee = function( valId ) {
  344. var intIndex = ( isNaN( valId ) ? parseInt( valId.replace( 'ZandboxRow-', '' ) ) : valId );
  345. log( 5, 'info', 'Function.prototype.updateMunzee() updating sandbox item %i-1 (from %o)', intIndex, valId );
  346. log( 4, 'log', 'Function.prototype.updateMunzee() updating munzee %s', munzeesandbox[ intIndex - 1 ][ 3 ] );
  347.  
  348. var objUpdatedMunzee = {
  349. lng: parseFloat( $( 'input#ZandboxRow-' + intIndex + '-lng' ).val() || map.getCenter().lng ),
  350. lat: parseFloat( $( 'input#ZandboxRow-' + intIndex + '-lat' ).val() || map.getCenter().lat ),
  351. name: ( $( 'input#ZandboxRow-' + intIndex + '-name' ).val() || 'Quick Deploy by " + username + "' ),
  352. id: ( $( 'input#ZandboxRow-' + intIndex + '-id' ).val() || ( intIndex - 1 ).toString() ),
  353. own: ( document.getElementById( 'ZandboxRow-' + intIndex + '-own' ).checked ? 1 : 0 )
  354. };
  355.  
  356. log( 4, 'log', 'Function.prototype.updateMunzee() updating marker on map from [ %o, %o ] to [ %o, %o ]',
  357. mapSandbox.list[ ( intIndex - 1 ) ].marker._lngLat.lng, mapSandbox.list[ ( intIndex - 1 ) ].marker._lngLat.lat, objUpdatedMunzee.lng, objUpdatedMunzee.lat
  358. );
  359. mapSandbox.list[ ( intIndex - 1 ) ].marker.setLngLat( [ objUpdatedMunzee.lng, objUpdatedMunzee.lat ] );
  360.  
  361. log( 4, 'log', 'Function.prototype.updateMunzee() updating mapSandbox.list[ %i ] (%s)', ( intIndex - 1 ), mapSandbox.list[ intIndex - 1 ].title );
  362. mapSandbox.list[ intIndex - 1 ].id = objUpdatedMunzee.id;
  363. mapSandbox.list[ intIndex - 1 ].title = objUpdatedMunzee.name;
  364. mapSandbox.list[ intIndex - 1 ].coordinates[ 0 ] = objUpdatedMunzee.lng;
  365. mapSandbox.list[ intIndex - 1 ].coordinates[ 1 ] = objUpdatedMunzee.lat;
  366. mapSandbox.list[ intIndex - 1 ].myOwn = objUpdatedMunzee.own;
  367. log( 4, 'info', 'Function.prototype.updateMunzee() updated %i in mapSandbox.list to:\n\t%o', ( intIndex - 1 ), mapSandbox.list[ intIndex - 1 ] );
  368.  
  369. log( 4, 'log', 'Function.prototype.updateMunzee() performing:\n\tmunzeesandbox[ %i ] = %o', ( intIndex - 1 ), [ objUpdatedMunzee.lng, objUpdatedMunzee.lat, objUpdatedMunzee.own, objUpdatedMunzee.name, objUpdatedMunzee.id ] );
  370. munzeesandbox[ intIndex - 1 ] = [ objUpdatedMunzee.lat, objUpdatedMunzee.lng, objUpdatedMunzee.own, objUpdatedMunzee.name, objUpdatedMunzee.id ];
  371.  
  372. log( 4, 'log', 'Function.prototype.updateMunzee() performing:\n\tFunction.saveSandbox()' );
  373. Function.saveSandbox();
  374. }
  375. Function.prototype.removeMunzee = function ( valId ) {
  376. var intIndex = ( isNaN( valId ) ? parseInt( valId.replace( 'ZandboxRow-', '' ) ) : valId );
  377. log( 4, 'log', 'Function.prototype.removeMunzee() removing munzee (%o) %i (%s) from sandbox.', valId, ( intIndex - 1 ), munzeesandbox[ intIndex - 1 ][ 3 ] );
  378.  
  379. log( 4, 'log', 'Function.prototype.removeMunzee() removing marker from map' );
  380. mapSandbox.list[ ( intIndex - 1 ) ].marker.remove();
  381.  
  382. log( 4, 'log', 'Function.prototype.removeMunzee() splicing %i (%s) from mapSandbox.list', ( intIndex - 1 ), mapSandbox.list[ intIndex - 1 ].title );
  383. mapSandbox.list.splice( ( intIndex - 1 ), 1 );
  384. log( 4, 'info', 'Function.prototype.removeMunzee() spliced %i from mapSandbox.list leaving:\n\t%o', ( intIndex - 1 ), mapSandbox.list );
  385.  
  386. log( 4, 'log', 'Function.prototype.removeMunzee() splicing %i (%s) from munzeesandbox', ( intIndex - 1 ), munzeesandbox[ intIndex - 1 ][ 3 ] );
  387. munzeesandbox.splice( ( intIndex - 1 ), 1 );
  388. log( 4, 'info', 'Function.prototype.removeMunzee() spliced %i from munzeesandbox leaving:\n\t%o', ( intIndex - 1 ), munzeesandbox );
  389.  
  390. log( 4, 'info', 'Function.prototype.removeMunzee() decrementing munzeesandboxcounter-- to %i', ( munzeesandboxcounter - 1 ) );
  391. munzeesandboxcounter--;
  392.  
  393. log( 4, 'log', 'Function.prototype.removeMunzee() performing:\n\tFunction.saveSandbox()' );
  394. Function.saveSandbox();
  395.  
  396. log( 4, 'log', 'Function.prototype.removeMunzee() performing:\n\tFunction.removeTableRow( %o )', intIndex );
  397. Function.removeTableRow( intIndex );
  398. }
  399. Function.prototype.addMunzee = function() {
  400. var objNewMunzee = {
  401. lng: ( $( 'input#NewMunzeeLng' ).val() || map.getCenter().lng ),
  402. lat: ( $( 'input#NewMunzeeLat' ).val() || map.getCenter().lat ),
  403. name: ( $( 'input#NewMunzeeName' ).val() || 'Quick Deploy by ' + username ),
  404. id: ( $( 'input#NewMunzeeId' ).val() || $( 'input#NewMunzeeId' )[ 0 ].placeholder ),
  405. own: ( document.getElementById( 'NewMunzeeOwn' ).checked ? 1 : 0 )
  406. };
  407.  
  408. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tmapSandbox.addItem( %o, %o, %o )', [ objNewMunzee.lng, objNewMunzee.lat ], objNewMunzee.name, objNewMunzee.own );
  409. mapSandbox.addItem( [ objNewMunzee.lng, objNewMunzee.lat ], objNewMunzee.name, objNewMunzee.own );
  410. mapSandbox.list[ mapSandbox.length - 1 ].marker.on( 'dragend', objDragged => pinMoved( objDragged ) );
  411. log( 2, 'log', 'Created move listener for pin #%i', ( mapSandbox.length - 1 ) );
  412. initilSB = 1;
  413.  
  414. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tmunzeesandbox.push( %o )', [ objNewMunzee.lat, objNewMunzee.lng, objNewMunzee.own, objNewMunzee.name, munzeesandboxcounter.toString() ] );
  415. munzeesandbox.push( [ objNewMunzee.lat, objNewMunzee.lng, objNewMunzee.own, objNewMunzee.name, munzeesandboxcounter.toString() ] );
  416. munzeesandboxcounter++;
  417. log( 4, 'info', 'munzeesandbox now contains:\n%o', munzeesandbox );
  418.  
  419. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.removeTableRow( \'%s\' )', 'ZandboxNewRow' );
  420. Function.removeTableRow( 'ZandboxNewRow' );
  421.  
  422. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.addTableRow( %o, %i )', munzeesandbox[ munzeesandboxcounter - 1 ], munzeesandboxcounter - 1 );
  423. $( 'table#ZandboxTable > tbody' ).append( Function.addTableRow( munzeesandbox[ munzeesandboxcounter - 1 ], munzeesandboxcounter - 1 ) );
  424.  
  425. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.createNewMunzeeRow()' );
  426. $( 'table#ZandboxTable > tbody' ).append( Function.createNewMunzeeRow() );
  427.  
  428. if ( isDebug ) {
  429. $( '.hidden-id' ).show();
  430. }
  431. log( 4, 'log', 'Function.prototype.addMunzee() performing:\n\tFunction.saveSandbox()' );
  432. Function.saveSandbox();
  433. }
  434. Function.prototype.clearSandbox = function() {
  435. log( 4, 'log', 'Function.prototype.clearSandbox clearing localStorage items.' );
  436. localStorage.removeItem( 'munzeesandboxcounter' );
  437. localStorage.removeItem( 'munzeesandbox' );
  438.  
  439. log( 4, 'log', 'Function.prototype.clearSandbox performing:\n\t$( \'tr#ZandboxNewRow\' ).remove()' );
  440. $( 'tr#ZandboxNewRow' ).remove();
  441.  
  442. log( 4, 'log', 'Function.prototype.clearSandbox clearing table rows.' );
  443. for ( var i = $( 'table#ZandboxTable > tbody > tr' ).length; i > 0; i-- ) {
  444. log( 4, 'log', 'Function.prototype.clearSandbox performing:\n\t$( \'tr#ZandboxRow-\' + %i ).remove()', i );
  445. $( 'tr#ZandboxRow-' + i ).remove();
  446. log( 4, 'log', 'Function.prototype.removeMunzee() removing marker from map' );
  447. mapSandbox.list[ i - 1 ].marker.remove();
  448. }
  449.  
  450. log( 4, 'log', 'Function.prototype.clearSandbox performing Function.createNewMunzeeRow()' );
  451. $( 'table#ZandboxTable > tbody' ).append( Function.createNewMunzeeRow() );
  452. }
  453.  
  454. var domZandboxDiv = document.createElement( 'div' );
  455. domZandboxDiv.id = 'zandbox';
  456. domZandboxDiv.className = 'panel-footer';
  457. domZandboxDiv.style = 'text-align: center;';
  458.  
  459. var domZandboxTable = document.createElement( 'table' );
  460. domZandboxTable.id = 'ZandboxTable';
  461. domZandboxTable.style = 'width: 100%;';
  462.  
  463. domZandboxTable.append( createTableHead() );
  464.  
  465. var domZandboxTableBody = document.createElement( 'tbody' );
  466.  
  467. munzeesandbox.forEach( function( arrSandPin, intIndex, arrSandbox ) {
  468. domZandboxTableBody.append( Function.addTableRow( arrSandPin, intIndex ) );
  469. } );
  470.  
  471. domZandboxTableBody.append( Function.createNewMunzeeRow() );
  472.  
  473. domZandboxTable.append( domZandboxTableBody );
  474. domZandboxDiv.append( domZandboxTable );
  475.  
  476. ( function() {
  477. 'use strict';
  478. log( 0, 'info', 'Script loaded.' );
  479.  
  480. $( 'div#filterboxes label' ).eq( 0 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 0 )[ 0 ].childNodes[ 2 ].nodeValue
  481. .replace( ' munzees', '' ).replace( 'exclude', 'hide' );// Shorten & clarify `exclude own munzees`
  482. $( 'div#filterboxes label' ).eq( 1 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 1 )[ 0 ].childNodes[ 2 ].nodeValue
  483. .replace( ' munzees', '' ).replace( 'exclude', 'hide' );// Shorten & clarify `exclude captured munzees`
  484. $( 'div#filterboxes label' ).eq( 4 )[ 0 ].childNodes[ 2 ].nodeValue = $( 'div#filterboxes label' ).eq( 4 )[ 0 ].childNodes[ 2 ].nodeValue
  485. .replace( 'only uncaptured', 'FTC opportunities' );// Clarify `only uncaptured`
  486. $( 'div#sandbox' ).remove();// We're not going to use the default sandbox buttons anymore.
  487.  
  488. $( 'input#showSBbuttons' ).click( function( event ) {
  489. event.preventDefault();
  490. $( 'div#showsandbox' ).empty();// hide button
  491. mapSandbox = initSandbox();// initialize sandbox
  492. var arrSandBoxMunzee = JSON.parse( localStorage.getItem( 'munzeesandbox' ) );
  493. for ( var n in arrSandBoxMunzee ) {
  494. mapSandbox.addItem( [ arrSandBoxMunzee[ n ][ 1 ], arrSandBoxMunzee[ n ][ 0 ] ], arrSandBoxMunzee[ n ][ 3 ], arrSandBoxMunzee[ n ][ 2 ] );
  495. mapSandbox.list[ n ].marker.on( 'dragend', objDragged => pinMoved( objDragged ) );
  496. log( 2, 'log', 'Created move listener for pin #%i', n );
  497. }
  498. $( 'div.panel.panel-default' ).append( domZandboxDiv );// Add table with contents of sandbox
  499.  
  500. if ( isDebug ) {
  501. $( '.hidden-id' ).show();
  502. }
  503. map.on( 'resize', mapChanged ).on( 'touchend', mapChanged ).on( 'dragend', mapChanged ).on( 'zoomend', mapChanged ).on( 'moveend', mapChanged );
  504. } );
  505. } )();