Normaliza nombres de lugares en Waze Map Editor (WME)
目前為
// ==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();
})();