WME Enhanced Actions

Streamlines editing tasks with automated apply and customizable save features. Configure settings directly from the Waze editor.

当前为 2024-09-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         WME Enhanced Actions
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Streamlines editing tasks with automated apply and customizable save features. Configure settings directly from the Waze editor.
// @author       Astheron
// @match        https://www.waze.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

/**
 * License and Credits:
 *
 * This script is licensed under the MIT License:
 *
 * Copyright (c) 2024 Astheron
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this script and associated documentation files (the "Script"), to deal
 * in the Script without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Script, and to permit persons to whom the Script is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Script.
 *
 * THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SCRIPT OR THE USE OR OTHER DEALINGS IN THE
 * SCRIPT.
 *
 * **Contact:** For more details or inquiries, you can contact the author, Astheron, on the Waze forum.
 */

(function() {
    'use strict';

    let autoSaveEnabled = JSON.parse(localStorage.getItem('autoSaveEnabled')) || false;
    let saveKey = localStorage.getItem('saveKey') || '';

    function initializeSidebarTab() {
        const { tabLabel, tabPane } = W.userscripts.registerSidebarTab("auto-save-toggle");

        tabLabel.innerText = 'Enhanced Actions';
        tabLabel.title = 'Configure Auto Save';

        tabPane.innerHTML = `
            <h2>WME Enhanced Actions</h2>
            <label>
                <input type="checkbox" id="autoSaveCheckbox"> Enable Auto Save
            </label>
            <br>
            <label for="saveKeyInput">Set Save Key:</label>
            <input type="text" id="saveKeyInput" maxlength="1" value="${saveKey}">
            <p>Press the key to save changes when enabled.</p>
        `;

        const checkbox = tabPane.querySelector('#autoSaveCheckbox');
        const saveKeyInput = tabPane.querySelector('#saveKeyInput');

        checkbox.checked = autoSaveEnabled;
        saveKeyInput.value = saveKey;

        checkbox.addEventListener('change', (event) => {
            autoSaveEnabled = event.target.checked;
            localStorage.setItem('autoSaveEnabled', JSON.stringify(autoSaveEnabled));
        });

        saveKeyInput.addEventListener('input', (event) => {
            saveKey = event.target.value.toUpperCase();
            localStorage.setItem('saveKey', saveKey);
        });

        W.userscripts.waitForElementConnected(tabPane).then(() => {
            console.log("Auto Save tab connected.");
        });
    }

    function handleEnterPress(event) {
        if (event.key === 'Enter' &&
            !(document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA')) {
            event.preventDefault();

            let applyButton = document.querySelector('wz-button.save-button');

            if (applyButton) {
                applyButton.click();
            } else {
                console.log("Apply button not found.");
            }
        }
    }

    function handleSaveKeyPress(event) {
        if (event.key.toUpperCase() === saveKey && autoSaveEnabled) {
            event.preventDefault();

            let saveButton = document.querySelector('wz-button#save-button');

            if (saveButton && saveButton.getAttribute('disabled') === "false") {
                saveButton.click();
            } else {
                console.log("Save button not found or disabled.");
            }
        }
    }

    function initializeMyUserscript() {
        initializeSidebarTab();
        document.addEventListener('keydown', handleEnterPress, true);
        document.addEventListener('keydown', handleSaveKeyPress, true);
    }

    if (W?.userscripts?.state.isReady) {
        initializeMyUserscript();
    } else {
        document.addEventListener("wme-ready", initializeMyUserscript, { once: true });
    }

})();

QingJ © 2025

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