WME Highlight Disconnected Non Driveable Segments

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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.06
// @grant               none
// @namespace https://greasyfork.org/users/177381
// ==/UserScript==

(function (){

function initialize()
{
    if ( !window.Waze.map )
    {
        setTimeout(initialize, 900);
        return;
    }
    myRank = W.loginManager.user.rank;
    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 segmentEditable(attributes, rank)
{
    if ( attributes.lockRank !== null )
        return ( attributes.lockRank <= rank );
    else
        return ( attributes.rank <= rank);
}

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]];
        if ( segment.selected || segment.state === "Update" || segment.state === "Insert" )
            continue;
        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 = -1;
        }
    }

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

var myRank;
setTimeout(initialize, 2000);

})();