Munzee Map Sandbox

Improves Munzee Map Sandbox

当前为 2023-07-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Munzee Map Sandbox
  3. // @namespace MunzeeMap
  4. // @version 1.13.1
  5. // @description Improves Munzee Map Sandbox
  6. // @author sohcah
  7. // @match https://www.munzee.com/map*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. $(function () {
  12. 'use strict';
  13.  
  14. setTimeout(() => {
  15. if("__CZ__BROWSEACTIONS" in window) {
  16. alert("You seem to have the CuppaZee Browse extension installed. Please disable the 'Munzee Map Sandbox' userscript and use the 'Better Map Sandbox' tool in Browse instead.");
  17. return;
  18. }
  19. }, 1000);
  20.  
  21. var hidden = [];
  22. window.maplibregl ||= new Proxy({}, {
  23. get: (target, prop) => {
  24. return window.mapboxgl?.[prop];
  25. }
  26. });
  27. window.mapboxgl ||= new Proxy({}, {
  28. get: (target, prop) => {
  29. return window.maplibregl?.[prop];
  30. }
  31. });
  32. window.toggleIcon = function(i) {
  33. if(hidden.includes(i)) {
  34. $(`.maplibregl-marker[style*="${i}"]`).css("visibility","visible");
  35. hidden = hidden.filter(x=>x!=i);
  36. } else {
  37. $(`.maplibregl-marker[style*="${i}"]`).css("visibility","hidden");
  38. hidden.push(i);
  39. }
  40. }
  41. var d = document.createElement('div');
  42. d.innerHTML = `<div id="filters"></div>`;
  43. var xd = d.firstChild;
  44. $('#inputbar')[0].append(xd)//${$('#inputbar')[0].innerHTML}`;
  45. setInterval(function () {
  46. var obj = {};
  47. var arr = Object.values(mapMarkers);
  48. $(`.maplibregl-marker[style*="${i}"]`).css("visibility","visible")
  49. for(var i of hidden) {
  50. $(`.maplibregl-marker[style*="${i}"]`).css("visibility","hidden")
  51. }
  52. for(var i = 0;i < arr.length;i++){
  53. var a = arr[i];
  54. var ic = a._element.style.backgroundImage.slice(5,-2);
  55. obj[ic] = (obj[ic]||0) + 1;
  56. //if(hidden.includes(ic)) {
  57. // a._element.style.visibility = "hidden"
  58. //} else {
  59. // a._element.style.visibility = "visible"
  60. //}
  61. }
  62. var x = Object.entries(obj);
  63. x.sort((a,b)=>b[1]-a[1]);
  64. var y = `<h4>Advanced Filtering Functionality is experimental</h4>`+x.map(i=>`
  65. <div onclick="toggleIcon('${i[0]}')" style="display:inline-block;border:1px solid ${hidden.includes(i[0])?'red':'green'};background-color:${hidden.includes(i[0])?'#ffaaaa':'#aaffaa'};padding:4px;margin:2px;border-radius:4px;">
  66. <img src="${i[0]}" style="height:32px;width:32px;"/><br/>
  67. ${i[1]}
  68. </div>
  69. `).join('');
  70. if($('#filters')[0].innerHTML.toLowerCase().replace(/[^0-9a-zA-Z]/g,'') != y.toLowerCase().replace(/[^0-9a-zA-Z]/g,'')) $('#filters')[0].innerHTML = y;
  71. },100)
  72. $('#showSBbuttons').click(function () {
  73. setTimeout(function () {
  74. mapSandbox.createItemElement = function (item) {
  75. var imageurl = 'https://i.ibb.co/3RKyg0m/Grey-Single-Surprise.png';
  76. var fn = htmlrep(username);
  77.  
  78. var el = document.createElement('div');
  79. el.className = 'marker map-box-sb-marker';
  80. el.style.width = `32px`;
  81. el.style.height = `32px`;
  82. el.style.cursor = 'pointer';
  83. el.style.setProperty('background-size',"32px 32px","important");
  84. el.style.zIndex ="10000000";
  85. el.style.backgroundImage = 'url('+imageurl+')';
  86. el.addEventListener('click', function (e) {
  87. e.stopPropagation();
  88. this.showItemPopup(item);
  89. }.bind(this));
  90. el.click();
  91. var bbtn = $('button.maplibregl-popup-close-button').click();
  92. return el;
  93. }
  94. mapSandbox.circles.basicScatter = { radius: 762, color: '#72ea5d' };
  95. mapSandbox.circles.catapultScatter = { radius: 402.336, color: '#b56000' };
  96. mapSandbox.circles.bowlingScatter = { radius: 228.6, color: '#00b52d' };
  97. mapSandbox.circles.joystickScatter = { radius: 457.2, color: '#b50087' };
  98. mapSandbox.circles.joystickSecondScatter = { radius: 213.36, color: '#8800b5' };
  99. mapSandbox.circles.capturePOI = { radius: 304.8, color: '#ff5500' };
  100. mapSandbox.showItemPopup = function (item) {
  101. map.panTo(item.coordinates);
  102. onCameraChanged();
  103. this.removePopup();
  104. this.selectedId = item.id;
  105.  
  106. this.itemPopup = new maplibregl.Popup({
  107. closeButton: false,
  108. offset: 10,
  109. anchor: "left",
  110. maxWidth: 400
  111. });
  112.  
  113. var itemContent = '<section id=\'createNewItem\' style=\'text-align:center;\'>';
  114. itemContent += '<input class="hidden-xs form-control" style=\'margin-bottom: 5px;\' id=\'popup_title\' type=\'text\' value=\'' + item.title + '\'>';
  115. //itemContent += '<input class="hidden-xs" style=\'margin-left: 10px;\' id=\'saveSBtitle\' type=\'button\' value=\'Save Title\'>';
  116. itemContent += '<input style=\'margin-right: 10px;background-color:#aaffaa;\' class=\'hidden-xs btn btn-md\' id=\'openquickdeploymodal\' type=\'button\' value=\'Deploy\' data-toggle="modal" data-target="#quickdeploy_modal">';
  117. itemContent += '<input class="hidden-xs btn btn-md" style=\'background-color:#ffaaaa;\' id=\'removeFromSB\' type=\'button\' value=\'Remove\'>';
  118. itemContent += '<span class="hidden-xs"><br />' + item.coordinates[1] + ' ' + item.coordinates[0] + '</span>';
  119.  
  120. if (item.myOwn) {
  121. itemContent += '<br />Own Munzee:<input style=\'margin-top: 5px; margin-left:10px;\' type=\'checkbox\' checked=\'checked\' id=\'check_SB_own\'/>';
  122. } else {
  123. itemContent += '<br />Own Munzee:<input style=\'margin-top: 5px; margin-left:10px;\' type=\'checkbox\' id=\'check_SB_own\'/>';
  124. }
  125. var captureAreas = ['virtual|captureArea|Virtual', 'poi_filter|capturePOI|POI', 'blast_capture|blastArea|Blast'].map(function (i) {
  126. return `<div style="display:inline-block;padding:4px;" id="newcheck_${i.split('|')[1]}"><img id="newcheckimg_${i.split('|')[1]}" style="height:36px;width:36px;filter:grayscale(1) opacity(0.4)" src="https://munzee.global.ssl.fastly.net/images/pins/${i.split('|')[0]}.png" /><br/><span style="color:red" id="newchecktext_${i.split('|')[1]}">${i.split('|')[2]}</span></div>`
  127. }).join('')
  128. itemContent += `<br /><div style="text-align:center;max-width:300px;"><div style="font-size:1.5em;font-weight:bold;color:green;">Capture Areas</div>${captureAreas}</div>`
  129.  
  130. var blockAreas = ['motel|motelArea|Motel/Trail','hotel|hotelArea|Hotel','virtualresort|resortArea|Resort','timeshare|tsArea|Timeshare','vacationcondo|condoArea|Condo','treehouse|treehouseArea|Treehouse','airmystery|airArea|Air Mystery','sirprizewheel|spwArea|Sir Prize Wheel'].map(function (i) {
  131. return `<div style="display:inline-block;padding:4px;" id="newcheck_${i.split('|')[1]}"><img id="newcheckimg_${i.split('|')[1]}" style="height:36px;width:36px;filter:grayscale(1) opacity(0.4)" src="https://munzee.global.ssl.fastly.net/images/pins/${i.split('|')[0]}.png" /><br/><span style="color:red" id="newchecktext_${i.split('|')[1]}">${i.split('|')[2]}</span></div>`
  132. }).join('')
  133. itemContent += `<div style="text-align:center;max-width:300px;"><div style="font-size:1.5em;font-weight:bold;color:red;">Blocked Areas</div>${blockAreas}</div>`
  134.  
  135. var scatterAreas = ['scatter|basicScatter|Default','catapult|catapultScatter|Catapult','bowlingball|bowlingScatter|Bowling','joystickfull|joystickScatter|Joystick','joystickfull|joystickSecondScatter|Joystick #2'].map(function (i) {
  136. return `<div style="display:inline-block;padding:4px;" id="newcheck_${i.split('|')[1]}"><img id="newcheckimg_${i.split('|')[1]}" style="height:36px;width:36px;filter:grayscale(1) opacity(0.4)" src="https://munzee.global.ssl.fastly.net/images/pins/${i.split('|')[0]}.png" /><br/><span style="color:red" id="newchecktext_${i.split('|')[1]}">${i.split('|')[2]}</span></div>`
  137. }).join('')
  138. itemContent += `<div style="text-align:center;max-width:300px;"><div style="font-size:1.5em;font-weight:bold;color:blue;">Scatter Areas</div>${scatterAreas}</div>`
  139. itemContent += '</section>';
  140. this.itemPopup.setLngLat(item.coordinates)
  141. .setHTML(itemContent)
  142. .addTo(map);
  143.  
  144. for (var layer in mapSandbox.list[mapSandbox.selectedId].layers) {
  145. if (mapSandbox.list[mapSandbox.selectedId].layers[layer]) {
  146. $('#newcheckimg_' + layer).css('filter', 'none');
  147. $('#newchecktext_' + layer).css('color', 'green');
  148. }
  149. }
  150.  
  151. $('#check_SB_own').change(function () {
  152. if (!this.checked) {
  153. mapSandbox.list[mapSandbox.selectedId].myOwn = 0;
  154. if (mapSandbox.list[mapSandbox.selectedId].layers.ownArea) {
  155. mapSandbox.removeLayer(mapSandbox.selectedId, 'ownArea');
  156. }
  157. } else {
  158. mapSandbox.list[mapSandbox.selectedId].myOwn = 1;
  159. if (circle) {
  160. mapSandbox.drawCircle(mapSandbox.selectedId, 'ownArea');
  161. }
  162. }
  163. });
  164.  
  165. function generate(layer) {
  166. return function () {
  167. if (!mapSandbox.list[mapSandbox.selectedId].layers[layer]) {
  168. mapSandbox.drawCircle(mapSandbox.selectedId, layer);
  169. $('#newcheckimg_' + layer).css('filter', 'none');
  170. $('#newchecktext_' + layer).css('color', 'green');
  171. } else {
  172. mapSandbox.removeLayer(mapSandbox.selectedId, layer);
  173. $('#newcheckimg_' + layer).css('filter', 'grayscale(1) opacity(0.4)');
  174. $('#newchecktext_' + layer).css('color', 'red');
  175. }
  176. }
  177. }
  178.  
  179. $('#newcheck_captureArea').click(generate('captureArea'));
  180. $('#newcheck_capturePOI').click(generate('capturePOI'));
  181. $('#newcheck_blastArea').click(generate('blastArea'));
  182.  
  183. $('#newcheck_motelArea').click(generate('motelArea'));
  184. $('#newcheck_hotelArea').click(generate('hotelArea'));
  185. $('#newcheck_resortArea').click(generate('resortArea'));
  186. $('#newcheck_tsArea').click(generate('tsArea'));
  187. $('#newcheck_condoArea').click(generate('condoArea'));
  188. $('#newcheck_treehouseArea').click(generate('treehouseArea'));
  189. $('#newcheck_airArea').click(generate('airArea'));
  190. $('#newcheck_spwArea').click(generate('spwArea'));
  191.  
  192. $('#newcheck_basicScatter').click(generate('basicScatter'));
  193. $('#newcheck_catapultScatter').click(generate('catapultScatter'));
  194. $('#newcheck_bowlingScatter').click(generate('bowlingScatter'));
  195. $('#newcheck_joystickScatter').click(generate('joystickScatter'));
  196. $('#newcheck_joystickSecondScatter').click(generate('joystickSecondScatter'));
  197.  
  198. $('#popup_title').change(function () {
  199. this.list[this.selectedId].title = $('#popup_title').val();
  200. }.bind(this));
  201.  
  202. $('#removeFromSB').click(function () {
  203. this.removeSelected();
  204. }.bind(this));
  205. let _this = this;
  206. $('#openquickdeploymodal').off().click(function () {
  207. _this.list[_this.selectedId].title = $('#popup_title').val();
  208. $('#quickdeployoptions').show();
  209. $('#quickdeploybody').empty();
  210. });
  211.  
  212. $('.qd-type').off().click(function () {
  213. quick_deploy(
  214. mapSandbox.list[mapSandbox.selectedId].marker.getLngLat().lat,
  215. mapSandbox.list[mapSandbox.selectedId].marker.getLngLat().lng,
  216. $(this).data('typeid'),
  217. mapSandbox.list[mapSandbox.selectedId].title
  218. );
  219. });
  220. }
  221. }, 250)
  222. });
  223. });