Munzee Map Sandbox

Improves Munzee Map Sandbox

当前为 2019-12-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         Munzee Map Sandbox
// @namespace    MunzeeMap
// @version      1.5
// @description  Improves Munzee Map Sandbox
// @author       sohcah
// @match        https://www.munzee.com/map*
// @grant        none
// ==/UserScript==

$(function () {
    'use strict';
    $('#showSBbuttons').click(function () {
        setTimeout(function () {
            mapSandbox.circles.basicScatter = { radius: 762, color: '#72ea5d' };
            mapSandbox.circles.catapultScatter = { radius: 402.336, color: '#b56000' };
            mapSandbox.circles.bowlingScatter = { radius: 228.6, color: '#00b52d' };
            mapSandbox.circles.joystickScatter = { radius: 457.2, color: '#b50087' };
            mapSandbox.circles.joystickSecondScatter = { radius: 213.36, color: '#8800b5' };
            mapSandbox.circles.capturePOI = { radius: 304.8, color: '#ff5500' };
            mapSandbox.showItemPopup = function (item) {
                this.removePopup();
                this.selectedId = item.id;

                this.itemPopup = new mapboxgl.Popup({
                    closeButton: true,
                    offset: 35
                });

                var itemContent = '<br> <section id=\'createNewItem\'>';
                itemContent += '<input class="hidden-xs" style=\'margin-bottom: 5px; width:180px;\' id=\'popup_title\' type=\'text\' value=\'' + item.title + '\'>';
                itemContent += '<input  class="hidden-xs" style=\'margin-left: 10px;\' id=\'saveSBtitle\' type=\'button\' value=\'Save Title\'>';
                itemContent += '<span class="hidden-xs"><br />' + item.coordinates[1] + ', ' + item.coordinates[0] + '</span>';

                if (item.myOwn) {
                    itemContent += '<br />Own Munzee:<input style=\'margin-top: 5px; margin-left:10px;\' type=\'checkbox\' checked=\'checked\' id=\'check_SB_own\'/>';
                } else {
                    itemContent += '<br />Own Munzee:<input style=\'margin-top: 5px; margin-left:10px;\' type=\'checkbox\' id=\'check_SB_own\'/>';
                }
                var captureAreas = ['virtual|captureArea|Virtual', 'poi_filter|capturePOI|POI', 'blast_capture|blastArea|Blast'].map(function (i) {
                    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>`
                }).join('')
                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>`

                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'].map(function (i) {
                    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>`
                }).join('')
                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>`

                var scatterAreas = ['scatter|basicScatter|Default','catapult|catapultScatter|Catapult','bowlingball|bowlingScatter|Bowling','joystickfull|joystickScatter|Joystick','joystickfull|joystickSecondScatter|Joystick #2'].map(function (i) {
                    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>`
                }).join('')
                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>`
                itemContent += '<br /><input style=\'margin-top: 5px; margin-right: 10px;\' class=\'hidden-xs\' id=\'openquickdeploymodal\' type=\'button\' value=\'Save & Quick Deploy\' data-toggle="modal" data-target="#quickdeploy_modal">';
                itemContent += '<input  class="hidden-xs" style=\'margin-top: 5px;\' id=\'removeFromSB\' type=\'button\' value=\'Remove Munzee\'>';
                itemContent += '</section>';
                this.itemPopup.setLngLat(item.coordinates)
                    .setHTML(itemContent)
                    .addTo(map);

                for (var layer in mapSandbox.list[mapSandbox.selectedId].layers) {
                    if (mapSandbox.list[mapSandbox.selectedId].layers[layer]) {
                        $('#newcheckimg_' + layer).css('filter', 'none');
                        $('#newchecktext_' + layer).css('color', 'green');
                    }
                }

                $('#check_SB_own').change(function () {
                    if (!this.checked) {
                        mapSandbox.list[mapSandbox.selectedId].myOwn = 0;
                        if (mapSandbox.list[mapSandbox.selectedId].layers.ownArea) {
                            mapSandbox.removeLayer(mapSandbox.selectedId, 'ownArea');
                        }
                    } else {
                        mapSandbox.list[mapSandbox.selectedId].myOwn = 1;
                        if (circle) {
                            mapSandbox.drawCircle(mapSandbox.selectedId, 'ownArea');
                        }
                    }
                });

                function generate(layer) {
                    return function () {
                        if (!mapSandbox.list[mapSandbox.selectedId].layers[layer]) {
                            mapSandbox.drawCircle(mapSandbox.selectedId, layer);
                            $('#newcheckimg_' + layer).css('filter', 'none');
                            $('#newchecktext_' + layer).css('color', 'green');
                        } else {
                            mapSandbox.removeLayer(mapSandbox.selectedId, layer);
                            $('#newcheckimg_' + layer).css('filter', 'grayscale(1) opacity(0.4)');
                            $('#newchecktext_' + layer).css('color', 'red');
                        }
                    }
                }

                $('#newcheck_captureArea').click(generate('captureArea'));
                $('#newcheck_capturePOI').click(generate('capturePOI'));
                $('#newcheck_blastArea').click(generate('blastArea'));

                $('#newcheck_motelArea').click(generate('motelArea'));
                $('#newcheck_hotelArea').click(generate('hotelArea'));
                $('#newcheck_resortArea').click(generate('resortArea'));
                $('#newcheck_tsArea').click(generate('tsArea'));
                $('#newcheck_condoArea').click(generate('condoArea'));
                $('#newcheck_treehouseArea').click(generate('treehouseArea'));
                $('#newcheck_airArea').click(generate('airArea'));

                $('#newcheck_basicScatter').click(generate('basicScatter'));
                $('#newcheck_catapultScatter').click(generate('catapultScatter'));
                $('#newcheck_bowlingScatter').click(generate('bowlingScatter'));
                $('#newcheck_joystickScatter').click(generate('joystickScatter'));
                $('#newcheck_joystickSecondScatter').click(generate('joystickSecondScatter'));

                $('#saveSBtitle').click(function () {
                    this.list[this.selectedId].title = $('#popup_title').val();
                }.bind(this));

                $('#removeFromSB').click(function () {
                    this.removeSelected();
                }.bind(this));
                let _this = this;
                $('#openquickdeploymodal').off().click(function () {
                    _this.list[_this.selectedId].title = $('#popup_title').val();
                    $('#quickdeployoptions').show();
                    $('#quickdeploybody').empty();
                });

                $('.qd-type').off().click(function () {
                    quick_deploy(
                        mapSandbox.list[mapSandbox.selectedId].marker.getLngLat().lat,
                        mapSandbox.list[mapSandbox.selectedId].marker.getLngLat().lng,
                        $(this).data('typeid'),
                        mapSandbox.list[mapSandbox.selectedId].title
                    );
                });
            }
        }, 1000)
    });
});