Map-Making Switcher

use shortcut to switch panoramas

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

您需要先安裝使用者腳本管理器擴展,如 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.0.6
// @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,isApplied=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
        }
        editor.openLocation(locs[currentIndex-1]);
        focusOnLoc(locs[currentIndex-1])
    }

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

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

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

    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()
            editor.save()
        };
        if (e.key === 'f' || e.key === 'F') {
            e.stopImmediatePropagation();
            getEditor()
            rewindSelections()
        };
    }
    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)
})();