WME Places Name Normalizer

Normaliza nombres de lugares en Waze Map Editor (WME)

当前为 2025-03-19 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         WME Places Name Normalizer
// @namespace    https://greasyfork.org/en/users/mincho77
// @version      1.0
// @description  Normaliza nombres de lugares en Waze Map Editor (WME)
// @author       mincho77
// @match        https://www.waze.com/*editor*
// @grant        none
// @license             MIT
// @run-at       document-end
// ==/UserScript==

(function() {
    "use strict";

    const SCRIPT_NAME = "PlacesNameNormalizer";
    const SCRIPT_VERSION = "1.0";

    function init() {
        console.log(`[${SCRIPT_NAME}] Initializing v${SCRIPT_VERSION}`);
        createSidebarTab();
        attachEvents();
    }

    function createSidebarTab() {
        const { tabLabel, tabPane } = W.userscripts.registerSidebarTab(SCRIPT_NAME);
        tabLabel.innerText = "Normalizer";
        tabLabel.title = "Normalize Waze Places";
        
        const tab = document.createElement("div");
        tab.id = "normalizer-tab";
        tab.innerHTML = `
            <h4>Place Normalizer <span style='font-size:11px;'>v${SCRIPT_VERSION}</span></h4>
            <button id="scan-places" class="btn btn-primary">Scan Places</button>
            <div id="normalizer-results" style="margin-top:10px;"></div>
            <button id="apply-normalization" class="btn btn-success" style="margin-top:10px;">Apply Changes</button>
        `;
        tabPane.appendChild(tab);
    }

    function attachEvents() {
        document.getElementById("scan-places").addEventListener("click", scanPlaces);
        document.getElementById("apply-normalization").addEventListener("click", applyNormalization);
    }

    function scanPlaces() {
        console.log("Scanning for places...");
        let resultsDiv = document.getElementById("normalizer-results");
        resultsDiv.innerHTML = "<p>Scanning...</p>";
        
        let venues = W.model.venues.getObjectArray();
        let foundPlaces = venues.filter(v => v.attributes.name && needsNormalization(v.attributes.name));
        
        resultsDiv.innerHTML = `<p>Found ${foundPlaces.length} places needing normalization.</p>`;
        
        let table = document.createElement("table");
        table.classList.add("table");
        table.innerHTML = `
            <thead>
                <tr>
                    <th>Select</th>
                    <th>Original Name</th>
                    <th>New Name</th>
                </tr>
            </thead>
            <tbody>
                ${foundPlaces.map((place, index) => `
                    <tr>
                        <td><input type='checkbox' class='place-checkbox' data-index='${index}'></td>
                        <td>${place.attributes.name}</td>
                        <td><input type='text' class='normalized-name' data-index='${index}' value='${normalizeName(place.attributes.name)}'></td>
                    </tr>
                `).join("")}
            </tbody>
        `;
        resultsDiv.appendChild(table);
    }

    function applyNormalization() {
        let checkboxes = document.querySelectorAll(".place-checkbox:checked");
        let updatedPlaces = [];

        checkboxes.forEach(cb => {
            let index = cb.dataset.index;
            let newName = document.querySelector(`.normalized-name[data-index='${index}']`).value;
            let place = W.model.venues.getObjectArray()[index];
            if (place) {
                place.attributes.name = newName;
                updatedPlaces.push(place);
            }
        });

        console.log("Updated Places:", updatedPlaces);
        alert("Normalization applied to selected places!");
    }

    function needsNormalization(name) {
        return /\b(el|la|los|las)\b/i.test(name);
    }

    function normalizeName(name) {
        return name.replace(/\b(el|la|los|las)\b/gi, "").trim();
    }

    init();
})();