Map-Making Switcher

use shortcut to switch panoramas

目前為 2024-08-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Map-Making Switcher
// @namespace    https://gf.qytechs.cn/users/1179204
// @description  use shortcut to switch panoramas
// @version      1.1.1
// @license      BSD
// @author       KaKa
// @match        *://map-making.app/maps/*
// @icon         https://www.svgrepo.com/show/521871/switch.svg
// ==/UserScript==
(function() {
    let editor,selections,currentIndex,map,mapListener,isApplied=false,customZoom=0.43,isCustom=false

    function getEditor() {
        editor = unsafeWindow.editor
        const activeSelections = editor.selections;
        const locations=unsafeWindow.locations
        selections = activeSelections.length > 0 ? activeSelections.flatMap(selection => selection.locations) : locations;
    }
    function switchLoc(locs) {

        if (!currentIndex) {
            currentIndex =1;
        } else {
            currentIndex +=1
            if (currentIndex>locs.length){
                currentIndex=1
            }
        }
        editor.openLocation(locs[currentIndex-1]);
        focusOnLoc(locs[currentIndex-1])
    }

    function rewindLoc(locs) {

        if (!currentIndex) {
            currentIndex =1;
        }
        else {
            currentIndex -=1
            if (currentIndex<1) currentIndex=selections.length
        }
        editor.openLocation(locs[currentIndex-1]);
        focusOnLoc(locs[currentIndex-1])
    }

    function focusOnLoc(loc){
        map=unsafeWindow.map
        map.setCenter(loc.location)
        map.setZoom(17)
    }

    function deleteLoc(loc){
        editor.closeAndDeleteLocation(loc)
    }

    function rewindSelections(loc){
        currentIndex=1
        editor.openLocation(selections[0])
    }

    function setZoom(z){
        if(z<0)z=0
        if(z>4)z=4
        const svControl=unsafeWindow.streetView
        svControl.setZoom(z)

    }

    function resetDefaultZoom(){
        if(mapListener) return
        map=unsafeWindow.map
        mapListener=function(){
            if(isCustom){
                let intervalId=setInterval(function(){
                    editor = unsafeWindow.editor
                    if(editor.currentLocation){
                        setZoom(customZoom)
                        clearInterval(intervalId)}
                },50);

            }
        }
        map.addListener('click', mapListener);
    }

    function getTag(index){

        const tags=unsafeWindow.editor.tags
        const result = Object.keys(tags).find(tag => tags[tag].order === index - 1)
        if(result){
            return result.trim()}
    }


    let onKeyDown = async (e) => {
        if(!isApplied) return
        if (e.key === 'q' || e.key === 'Q') {
            e.stopImmediatePropagation();
            getEditor()
            switchLoc(selections)
        };
        if (e.key === 'e' || e.key === 'E') {
            e.stopImmediatePropagation();
            getEditor()
            rewindLoc(selections)
        };
        if (e.key === 'c' || e.key === 'C') {
            e.stopImmediatePropagation();
            getEditor()
            deleteLoc(selections[currentIndex-1])
        };
        if (e.key === 'r' || e.key === 'R') {
            e.stopImmediatePropagation();
            getEditor()
            rewindSelections()
        };
        if (e.key === 'g' || e.key === 'G') {
            e.stopImmediatePropagation();
            resetDefaultZoom()
            if(!isCustom) {
                var input = prompt('please enter a zoom value(0-4):');

                var parsedValue = parseFloat(input);

                if (isNaN(parsedValue)) {
                    alert('The input is not a valid zoom! Please try again.');
                    isCustom=false
                } else {
                    customZoom=parsedValue
                    isCustom=true
                    resetDefaultZoom()
                    alert('Custom zoom has been applied!');
                }
            }
            else {
                isCustom=false
                alert('Zoom customizing is cancelled!')}
        }
    }
    document.addEventListener("keydown", onKeyDown);

    var shortCutButton = document.createElement('button');
    shortCutButton.textContent = 'ShortCut Off';
    shortCutButton.style.position = 'fixed';
    shortCutButton.style.top = '12px';
    shortCutButton.style.right = '500px';
    shortCutButton.style.zIndex = '9999';
    shortCutButton.style.borderRadius = "18px";
    shortCutButton.style.padding = "10px 20px";
    shortCutButton.style.border = "none";
    shortCutButton.style.backgroundColor = "#4CAF50";
    shortCutButton.style.color = "white";
    shortCutButton.style.cursor = "pointer";
    shortCutButton.addEventListener('click', function(){
        if(isApplied){
            isApplied=false
            shortCutButton.style.border='none'
            shortCutButton.textContent = 'ShortCut Off';
        }
        else {isApplied=true
              shortCutButton.textContent = 'ShortCut On';
              shortCutButton.style.border='2px solid #fff'}

    });
    document.body.appendChild(shortCutButton)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址