WME Highlight Disconnected Non Driveable Segments

Rózsaszínre színezi a be nem kötött nem navigálható utakat

ของเมื่อวันที่ 31-03-2018 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name                WME Highlight Disconnected Non Driveable Segments
// @description         Rózsaszínre színezi a be nem kötött nem navigálható utakat
// @include             https://www.waze.com/*/editor*
// @include             https://www.waze.com/editor*
// @include             https://beta.waze.com/*
// @exclude             https://www.waze.com/*user/*editor/*
// @version             1.0
// @grant               none
// @namespace https://greatest.deepsurf.us/users/177381
// ==/UserScript==

(function (){

function initialize()
{
    if ( !window.Waze.map )
    {
        setTimeout(initialize, 900);
        return;
    }
    window.setInterval(highlight, 1000);
}

function removeSegID(ID, list)
{
    for ( var i = 0; i < list.length; ++i )
        if ( list[i] == ID )
        {
            list.splice(i, 1);
            break;
        }
}

function segmentIsDriveable(attributes)
{
    return ( attributes.roadType != 5 && attributes.roadType != 10 && attributes.roadType != 16 );
}

function driveableSegmentOnNode(nodeid)
{
    var node = W.model._roadGraph._nodeRepository.objects[nodeid];
    if ( typeof node === "undefined" )
        return false;
    var segIDs = node.attributes.segIDs;
    for ( var i = 0; i < segIDs.length; ++i )
    {
        var segment = W.model.segments.objects[segIDs[i]];
        if ( typeof segment === "undefined" )
            continue;
        if ( segmentIsDriveable(segment.attributes) )
            return true;
    }
    return false;
}

function segmentConnectedToDriveable(attributes)
{
    return ( driveableSegmentOnNode(attributes.fromNodeID) ||
             driveableSegmentOnNode(attributes.toNodeID) );
}

function segmentInList(segID, segIDList)
{
    for ( var i = 0; i < segIDList.length; ++i )
        if ( segIDList[i] == segID )
            return true;
    return false;
}

function colorSegments(segIDs, color, opacity)
{
    for ( var i = 0; i < segIDs.length; ++i )
    {
        var segment = W.model.segments.objects[segIDs[i]];
        var line = document.getElementById(segment.geometry.id);
        if ( line === null )
            continue;
        line.setAttribute("stroke", color);
        line.setAttribute("stroke-opacity", opacity);
        line.setAttribute("stroke-dasharray", "none");
    }
}

function highlight(event)
{
    function moveSegmentsToConnectedFromPartition(segID)
    {
        var nodes = W.model._roadGraph._nodeRepository.objects;
        var tobemovedlist = [segID];
        while ( tobemovedlist.length > 0 )
        {
            var movedid = tobemovedlist.pop();
            removeSegID(movedid, notconnected);
            connected.push(movedid);

            var attributes = W.model.segments.objects[movedid].attributes;
            var fromNode = nodes[attributes.fromNodeID], toNode = nodes[attributes.toNodeID];
            var connectingSegIDs = [];
            if ( typeof fromNode !== "undefined" )
                connectingSegIDs = connectingSegIDs.concat(fromNode.attributes.segIDs);
            if ( typeof toNode !== "undefined" )
                connectingSegIDs = connectingSegIDs.concat(toNode.attributes.segIDs);
            for ( var i = 0; i < connectingSegIDs.length; ++i )
            {
                var id = connectingSegIDs[i];
                if ( !segmentInList(id, tobemovedlist) && segmentInList(id, notconnected) )
                    tobemovedlist.push(id);
            }
        }
    }

    if ( Waze.map.zoom <= 3 )
        return;

    var connected = [], notconnected = [];

    var segments = W.model.segments.objects;
    for ( var id in segments )
        if ( segments.hasOwnProperty(id) && !segmentIsDriveable(segments[id].attributes) )
            notconnected.push(id);
    for ( var i = 0; i < notconnected.length; ++i )
    {
        var id = notconnected[i];
        var attributes = W.model.segments.objects[id].attributes;
        if ( segmentConnectedToDriveable(attributes) )
        {
            moveSegmentsToConnectedFromPartition(id);
            i = 0;
        }
    }

    colorSegments(connected, "#00ff00", 0.0);
    colorSegments(notconnected, "#ff3cdd", 0.7);
}

setTimeout(initialize, 2000);

})();