Greasy Fork 还支持 简体中文。

Map-Making Switcher

use shortcut to switch panoramas

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Map-Making Switcher
// @namespace    https://greasyfork.org/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)
})();