您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
changes the styling of the segment and venue messages
当前为
// ==UserScript== // @name WME Simple Alert Messages // @namespace https://fxzfun.com/ // @version 3.1 // @description changes the styling of the segment and venue messages // @author FXZFun // @match https://*.waze.com/*/editor* // @match https://*.waze.com/editor* // @exclude https://*.waze.com/user/editor* // @icon https://www.google.com/s2/favicons?sz=64&domain=waze.com // @grant none // @license GNU GPL v3 // ==/UserScript== /* global W, OpenLayers, trustedTypes */ (function() { 'use strict'; const DEBUG = false; class Messages { static LOCKED = "locked"; static EA = "ea"; static MIXED = "mixed"; static PUR = "pur"; static CLOSURE = "closure"; static HIDE_MESSAGE = "hide_message"; static messages = { "locked": { "icon": "w-icon-lock-fill", "message": "Locked to L{maxLock}" }, "ea": { "icon": "w-icon-alert-fill", "message": "Out of your EA" }, "mixed": { "icon": "w-icon-round-trip", "message": "Mixed A/B" }, "pur": { "icon": "w-icon-location-update-fill", "message": "PUR Request" }, "closure": { "icon": "w-icon-closure", "message": "Has Closures" } } static getMessage(type, maxLock='') { return this.messages?.[type]?.message?.replace('{maxLock}', maxLock); } static getIcon(type) { return this.messages?.[type]?.icon; } } class MessageContainer { container; constructor() { this.container = document.getElementById("wmeSamContainer") || document.createElement("div"); if (!document.getElementById("wmeSamContainer")) { this.container.id = "wmeSamContainer"; document.querySelector("#edit-panel wz-tabs").insertAdjacentElement("beforeBegin", this.container); } } reset() { this.container.innerHTML = policy.createHTML(""); } addMessage(messageType, maxLock='') { this.container.insertAdjacentHTML("beforeEnd", policy.createHTML(`<span class="wmeSamMessage ${messageType}"><i class="w-icon ${Messages.getIcon(messageType)}"></i> ${Messages.getMessage(messageType, maxLock) ?? ''}</span>`)); } } const policy = trustedTypes.createPolicy('wmeSamPolicy', { createHTML: (input) => input}); function getUrl() { let center = W.map.getCenter(); let lonlat = new OpenLayers.LonLat(center.lon, center.lat); lonlat.transform(new OpenLayers.Projection('EPSG:900913'), new OpenLayers.Projection('EPSG:4326')); let zoom = W.map.getZoom(); let features = W.selectionManager.getSelectedFeatures(); let featureType = features[0].model.type; features = features.map(f => f.model.attributes.id); let url = location.href.split("?")[0] + `?env=${W.map.wazeMap.regionCode}&lat=${lonlat.lat}&lon=${lonlat.lon}&zoomLevel=${zoom}`; if (features.length > 0) url += `&${featureType}s=${features.join(",")}`; return url; } function getCity() { var city = document.querySelector(".location-info").innerText.split(",")[0]; if (document.querySelector(".wmecitiesoverlay-region") != null) city = document.querySelector(".wmecitiesoverlay-region").innerText; return city; } function addLockRequestCopier(maxLock) { let chip = document.querySelector(".locked"); chip.addEventListener("click", () => { navigator.clipboard.writeText(`:unlock${maxLock}: ${getCity()} - *reason* - <${getUrl()}>`); chip.innerHTML = policy.createHTML(`<span class="wmeSamMessage locked"><i class="w-icon w-icon-copy"></i> Copied!</span>`); }); } function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function getPanel() { for (let i = 0; i < 100; i++) { const panel = document.querySelector("#edit-panel"); const tabs = document.querySelector("#edit-panel wz-tabs"); if (panel && tabs) return panel; await sleep(100); } } async function processSelectionChange() { let selected = W.selectionManager.getSelectedFeatures(); let userRank = W?.loginManager?.user?.rank; let maxLockRank = Math.max(...selected.map(item => item?.data?.wazeFeature?._wmeObject?.getLockRank())); if (selected.length === 0) return; // wait for panel to open let panel = await getPanel(); if (!panel) { console.error("WME SAM: Could not open panel"); return; } // add or clear message container let messageContainer = new MessageContainer(); messageContainer.reset(); const wzAlerts = Array.from(document.querySelector('wz-alerts-group')?.children || []); wzAlerts.forEach(wzAlert => { let messageType; if (userRank < maxLockRank) messageType = Messages.LOCKED; if (wzAlert?.innerHTML?.includes('driven area') || (maxLockRank <= userRank && wzAlert?.innerHTML?.includes('editing area')) || (maxLockRank <= userRank && !selected[0]?.model?.arePropertiesEditable?.())) messageType = Messages.EA; if (wzAlert?.classList?.contains('inconsistent-direction-alert')) messageType = Messages.MIXED; if (wzAlert?.innerHTML?.includes('pending')) messageType = Messages.PUR; if (wzAlert?.innerHTML?.includes('closure')) messageType = Messages.CLOSURE; if (wzAlert?.innerHTML?.includes('reviewed')) messageType = Messages.HIDE_MESSAGE; if (!!messageType) { if (messageType !== Messages.HIDE_MESSAGE) messageContainer.addMessage(messageType, maxLockRank + 1); if (!DEBUG) wzAlert?.classList?.add("hide"); } if (messageType === Messages.LOCKED) addLockRequestCopier(maxLockRank + 1); if (messageType === Messages.PUR) document.querySelector(".wmeSamMessage.pur").addEventListener("click", () => { document.querySelector(".venue-alerts wz-alert span[slot=action]").click(); }); }); // hide message box if no unhandled alerts const wzAlertsGroup = document.querySelector("wz-alerts-group"); const visibleAlerts = Array.from(wzAlertsGroup?.children || []).filter(_ => _?.classList.contains('hide') === false); if (visibleAlerts.length === 0) { wzAlertsGroup.classList.add('hide'); } // out of ea venue if (visibleAlerts.length === 0 && (!selected?.[0]?.attributes?.repositoryObject?.isGeometryEditable?.())){ // messageContainer.addMessage(Messages.EA); // this is causing issue right now, debug later } } function initialize() { console.log("WME SAM: Loaded"); W.selectionManager.events.register('selectionchanged', this, processSelectionChange); // run preselected features from url if (W.selectionManager.getSelectedFeatures().length > 0) processSelectionChange(); // add styling let style = document.createElement("style"); style.innerHTML = policy.createHTML(`/* WME Simple Alert Messages Styling */ #wmeSamContainer {padding-top: 10px;} .wmeSamMessage {padding: 7px 10px; border-radius: 10px; width: fit-content; margin-left: 5px; white-space: nowrap;} .wmeSamMessage .w-icon {font-size: 20px;vertical-align: middle;} .wmeSamMessage.locked {background-color: #FE5F5D; cursor: pointer;} .wmeSamMessage.ea {background-color: #FF9800;} .wmeSamMessage.mixed {background-color: #42A5F5;} .wmeSamMessage.pur {background-color: #C9B5FF; cursor: pointer;} .wmeSamMessage.closure {background-color: #FE5F5D; cursor: pointer;}`); document.body.appendChild(style); } // bootstrap W?.userscripts?.state?.isReady ? initialize() : document.addEventListener("wme-ready", initialize, { once: true }); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址