Zandboxee

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

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

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