Opens StreetView.vn (Ctrl+Alt+F), Mapillary (Ctrl+Alt+G), or OSM (Ctrl+Alt+H) at the current WME map center and zoom level.
当前为
// ==UserScript==
// @name WME Openers (StreetView.vn, Mapillary, OSM)
// @version 1.0.4
// @description Opens StreetView.vn (Ctrl+Alt+F), Mapillary (Ctrl+Alt+G), or OSM (Ctrl+Alt+H) at the current WME map center and zoom level.
// @author Minh Tan
// @match https://www.waze.com/editor*
// @match https://www.waze.com/*/editor*
// @match https://beta.waze.com/editor*
// @match https://beta.waze.com/*/editor*
// @exclude https://www.waze.com/user/editor*
// @exclude https://www.waze.com/*/user/editor*
// @grant none
// @noframes
// @license MIT
// @namespace https://greasyfork.org/users/1440408
// ==/UserScript==
(function() {
'use strict';
// Function to get coordinates in WGS84 (EPSG:4326)
function getWGS84Center() {
if (!window.W || !window.W.map || !window.W.map.getCenter) {
console.error("WME Openers: WME map object (W.map) not available.");
return null;
}
const mapCenter = window.W.map.getCenter(); // Center in Web Mercator (EPSG:900913)
try {
const proj900913 = new OpenLayers.Projection("EPSG:900913");
const proj4326 = new OpenLayers.Projection("EPSG:4326");
// Create a LonLat object and transform it from Web Mercator to WGS84
const lonLat = new OpenLayers.LonLat(mapCenter.lon, mapCenter.lat);
const transformedLonLat = lonLat.transform(proj900913, proj4326);
return {
lat: transformedLonLat.lat,
lng: transformedLonLat.lon
};
} catch (e) {
console.error("WME Openers: Error transforming coordinates:", e);
return null;
}
}
// Function to get the current zoom level from Waze
function getWazeZoom() {
if (!window.W || !window.W.map || typeof window.W.map.getZoom !== 'function') {
console.error("WME Openers: WME map object (W.map) or getZoom function not available.");
return null;
}
return window.W.map.getZoom();
}
function handleShortcut(event) {
const isCtrl = event.ctrlKey;
const isAlt = event.altKey; // Corrected from isShift and alttKey
const isFKey = event.key === 'f' || event.key === 'F';
const isGKey = event.key === 'g' || event.key === 'G';
const isHKey = event.key === 'h' || event.key === 'H';
const isMacCmd = event.metaKey;
const openStreetView = (isCtrl || isMacCmd) && isAlt && isFKey;
const openMapillary = (isCtrl || isMacCmd) && isAlt && isGKey;
const openOSM = (isCtrl || isMacCmd) && isAlt && isHKey;
if (openStreetView || openMapillary || openOSM) {
event.preventDefault();
event.stopPropagation();
const coords = getWGS84Center();
const zoom = getWazeZoom(); // Get current Waze zoom level
if (coords && zoom !== null) {
if (openStreetView) {
// Assuming StreetView.vn might accept a 'z' or 'zoom' parameter.
const url = `https://www.streetview.vn/?lat=${coords.lat}&lng=${coords.lng}&z=${zoom}`;
window.open(url, '_blank');
console.log(`WME Openers: Opened StreetView.vn: ${url}`);
} else if (openMapillary) {
const mapillaryUrl = `https://www.mapillary.com/app/?lat=${coords.lat}&lng=${coords.lng}&z=${zoom}`;
window.open(mapillaryUrl, '_blank');
console.log(`WME Openers: Opened Mapillary: ${mapillaryUrl}`);
} else if (openOSM) {
const osmUrl = `https://www.openstreetmap.org/edit#map=${zoom}/${coords.lat}/${coords.lng}`;
window.open(osmUrl, '_blank');
console.log(`WME Openers: Opened OpenStreetMap: ${osmUrl}`);
}
} else {
console.warn("WME Openers: Could not retrieve WME map coordinates or zoom level.");
}
}
}
function init() {
document.addEventListener('keydown', handleShortcut);
console.log("WME Openers (StreetView.vn, Mapillary, OSM) script loaded. Use Ctrl+Alt+[F,G,H]");
}
// Wait for WME to be ready
if (window.W && window.W.map) {
init();
} else {
document.addEventListener('wme-initialized', init, { once: true });
}
})();