WME Highlight Disconnected Non Driveable Segments

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);

})();