Map-Making Switcher

use shortcut to switch panoramas

As of 2024-08-12. See the latest version.

// ==UserScript==
// @name         Map-Making Switcher
// @namespace    https://greasyfork.org/users/1179204
// @description  use shortcut to switch panoramas
// @version      1.0.1
// @license      BSD
// @author       KaKa
// @match        *://map-making.app/maps/*
// @icon         https://www.svgrepo.com/show/521871/switch.svg
// ==/UserScript==
(function() {
    let editor,locations,selections,currentLoc

    function getEditor(){
        editor=unsafeWindow.editor
        locations=unsafeWindow.locations
        const selectedLocs=editor.selections
        selectedLocs.forEach(selection =>{
        selections=[...selection.locations]
        })
    }

    function switchLoc(locs) {
        if (!currentLoc) {
            currentLoc = locs[0];
        } else {
            const index = locs.indexOf(currentLoc);
            currentLoc = (index + 1 === locs.length) ? locs[0] : locs[index + 1];
        }
        editor.openLocation(currentLoc);
    }

    let onKeyDown = (e) => {
        if (e.key === 'e' || e.key === 'E') {
            e.stopImmediatePropagation();
            getEditor()
            switchLoc(locations)
        };
        if (e.key === 'q' || e.key === 'Q') {
            e.stopImmediatePropagation();
            getEditor()
            switchLoc(selections)
        };
    }
    document.addEventListener("keydown", onKeyDown);
})();