Modify the Waze & User trace displayed by URs
当前为
// ==UserScript==
// @name Modify Traces
// @namespace https://greatest.deepsurf.us/users/30701-justins83-waze
// @version 0.1
// @description Modify the Waze & User trace displayed by URs
// @author JustinS83
// @include https://www.waze.com/editor*
// @include https://www.waze.com/*/editor*
// @include https://beta.waze.com*
// @exclude https://www.waze.com/*user/editor*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var URMO;
function bootstrap(tries = 1) {
if (W &&
W.map &&
W.model &&
W.loginManager.user &&
$) {
init();
} else if (tries < 1000) {
setTimeout(function () {bootstrap(tries++);}, 200);
}
}
bootstrap();
function modifyRules(){
getTraceLayer().then(val => {
//In theory these are always the same index - but better to search and be sure we get the right ones
let sugRouteArrowIndex = val.styleMap.styles.default.rules.findIndex(function(e){ return e.filter.value == "suggestedRouteArrow";});
let sugRouteIndex = val.styleMap.styles.default.rules.findIndex(function(e){ return e.filter.value == "suggestedRoute";});
let userRouteArrowIndex = val.styleMap.styles.default.rules.findIndex(function(e){ return e.filter.value == "driveArrow";});
let userRouteIndex = val.styleMap.styles.default.rules.findIndex(function(e){ return e.filter.value == "drive";});
//Waze suggested route
//default is 5
val.styleMap.styles.default.rules[sugRouteArrowIndex].symbolizer.graphicHeight = 8;
//default is 9
val.styleMap.styles.default.rules[sugRouteArrowIndex].symbolizer.graphicWidth = 12;
//User driven route
//default is 5
val.styleMap.styles.default.rules[userRouteArrowIndex].symbolizer.graphicHeight = 8;
//default is 9
val.styleMap.styles.default.rules[userRouteArrowIndex].symbolizer.graphicWidth = 12;
//This would change the route color from dark purple
//val.styleMap.styles.default.rules[sugRouteIndex].symbolizer.strokeColor = "#c77aff";
val.redraw();
URMO.disconnect(); //We only need the MO to fire once - once the rule is set it persists on the layer. The layer isn't created until the first time a user clicks on a UR, though.
});
}
function getTraceLayer(tries = 1) { //Need to use a promise to get the layer - if we do not we have to fudge some delay after clicking to wait until the layer is created and everything set up before we go through our changes
return new Promise((resolve, reject) => {
if (W.map.getLayersByName("problemMoreInfo").length > 0) {
resolve(W.map.getLayersByName("problemMoreInfo")[0]);
} else {
if(tries <= 10)
setTimeout(() => resolve(getTraceLayer(tries++)), 100);
}
});
}
function URLayerPopulated()
{
for(var mObj in W.map.updateRequestLayer.markers)
{
if(W.map.updateRequestLayer.markers.hasOwnProperty(mObj))
{
var mIcon = W.map.updateRequestLayer.markers[mObj].icon.div;
mIcon.addEventListener("click", modifyRules, false);
}
}
}
function init(){
URMO = new MutationObserver(URLayerPopulated);
URMO.observe(W.map.updateRequestLayer.div,{childList : true});
}
})();