Zandboxee

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

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

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