WME FixingMap Plugin

Find errors in the map

Version au 09/12/2018. Voir la dernière version.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name         WME FixingMap Plugin
// @description  Find errors in the map
// @include      /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @namespace    https://www.waze.com/ar/editor
// @version      0.9
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAH+SURBVGhD1Ze9TQQxEIX3rgKEhAgQIqICEqqADkhpgCIIiEkogBSoAiE6IEIcAQlQAQdv8Zx29/zzbM/6vJ+0ugku+N54vGvPLpudZVOA88WNqdLY2js1VZ+5+a0alzwoEiCn+z55MOoIjTU2XdQD5EoLjDxQC6AlDlh5kB1AUxzEyH+/36cF0JYWYuRBdIBaxAHkARVgLHGQIw+CARj5n+MLU/mZP16Z6p9ceeAMwHadle+y/fZiKp6huGANoNl1FzEhXPJg7ShRQh587h+ayo9PHvQClJIXQiFC8mAVoLS8YAsBcUYetAHYDctwcrDbe2JhxYXZ1+KO+pCFuh+SfXj9MJUdbOpYeVDkPsCQIg9UAjCjkjJOPp6ub9unmhWIAeLC5AJ05cGkAgzlgUqA0BsGMP/xYZMHk1gBlzxQ+w4Iw7cN2/nhURv4xAUqgJzb2QNYLKnyIDhCKZeOHCDOygPvCtjktVdBuh8j3cUZwNd5rRCQTxUXrAGYsckN8Xx2ZKo81vYAO/Mp91pBSx70ViBmw3ZPj+wrVlNcWAVIlWfInXMfbYCx5McUF6ICsPIlxIXZ8g9Te6lRHlCHuVrlAbUCoQCbEBeCK1CzPPAGqF0eUHvARg3ywBmA3bibxhpgCqMjRI9QTfJgLcBURkfoBZiaPLBeaFzUNj5N0zS/umsXLLJwKl8AAAAASUVORK5CYII=
// @match        https://www.waze.com/ar/editor/*
// @match        https://www.waze.com/ar/editor
// @match        https://www.waze.com/editor/*
// @match        https://www.waze.com/editor
// @grant        none
// @author       Sultan Alrefaei
// @copyright    2018 - 2019 Sultan Alrefaei <@sultan_alrefaei>
// ==/UserScript==

//Styles
var btn_rn = "width: 50px;" 
            +"height: 30px;"
            +"border: none;"
            +"background-color: #9E9E9E;"
            +"color: white;";

var stateNode = false;
var stateRoad = false;

window.onload = e =>{
    createTap();
    window.W.map.events.register("move", null, e =>{
        setTimeout(manager, 500);
    });
    getElement("#WMETB_Select_In_Landmark").addEventListener("click", manager);
}

const manager = e =>{
    if (W.map.zoom >= 3){
        if (stateNode){
            checkNodeIfConnection();
        }
        if (stateRoad){
            checkIfRoadSelect();
        }
    }
}

const checkIfRoadSelect = e =>{
    var segs = [];
    for (seg in W.model.segments.objects){
        if (W.model.segments.objects[seg].selected){
            segs.push(W.model.segments.objects[seg]);
        }
    }
    setTimeout(checkIfRoadOnRoad(segs), 10);
}

const checkIfRoadOnRoad = segs =>{
    for (var s1 = 0; s1 < segs.length; s1++){
        for (var s2 = 0; s2 < segs.length; s2++){
            if (segs[s1].attributes.id != segs[s2].attributes.id && segs[s1].attributes.fromNodeID == segs[s2].attributes.fromNodeID && segs[s1].attributes.toNodeID == segs[s2].attributes.toNodeID){
                if (getElement("#" + segs[s1].attributes.geometry.id) != null){
                    getElement("#" + segs[s1].attributes.geometry.id).setAttribute("stroke", "red");
                    getElement("#" + segs[s1].attributes.geometry.id).setAttribute("stroke-opacity", 1);
                }
                if (getElement("#" + segs[s2].attributes.geometry.id) != null){
                    getElement("#" + segs[s2].attributes.geometry.id).setAttribute("stroke", "red");
                    getElement("#" + segs[s2].attributes.geometry.id).setAttribute("stroke-opacity", 1);
                }
            }
        }
    }
}

const checkNodeIfConnection = e =>{
    for (node in W.model.nodes.objects){
        if (W.model.nodes.objects[node].attributes.segIDs.length == 1){
            if (getElement("#" + W.model.nodes.objects[node].attributes.geometry.id) != null){
                getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("fill", "#525252");
                getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("fill-opacity", 1);

                getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("stroke", "red");
                getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("stroke-opacity", 1);
            }
        }
    }
}

const defaultNode = e =>{
    for (node in W.model.nodes.objects){
        if (getElement("#" + W.model.nodes.objects[node].attributes.geometry.id) != null){
            getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("fill", "");
            getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("fill-opacity", 0);

            getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("stroke", "");
            getElement("#" + W.model.nodes.objects[node].attributes.geometry.id).setAttribute("stroke-opacity", 0);
        }
    }
}

const checkLevel = e =>{
    for ( lvl in W.model.segments.objects){
        if (getElement("#" + W.model.segments.objects[lvl].attributes.geometry.id) != null){
            var useridCreator = W.model.segments.objects[lvl].attributes.createdBy;
            var useridUpdator = W.model.segments.objects[lvl].attributes.updatedBy;
            if (W.model.users.objects[useridCreator].normalizedLevel == 1){
                getElement("#" + W.model.segments.objects[lvl].attributes.geometry.id).setAttribute("stroke", "green");
                getElement("#" + W.model.segments.objects[lvl].attributes.geometry.id).setAttribute("stroke-opacity", 1);
            }else if (W.model.users.objects[useridUpdator].normalizedLevel == 2){
                getElement("#" + W.model.segments.objects[lvl].attributes.geometry.id).setAttribute("stroke", "blue");
                getElement("#" + W.model.segments.objects[lvl].attributes.geometry.id).setAttribute("stroke-opacity", 1);
            }
        }
    }
}

const cameras = e =>{
    for (cam in W.model.cameras.objects){
        if (W.model.cameras.objects[cam].attributes.geometry.id != null){
            if (W.model.cameras.objects[cam].attributes.speed == 100)
            getElement("#" + W.model.cameras.objects[cam].attributes.geometry.id).setAttribute("xlink:href", "https://www.dropbox.com/s/oiydd8av9111xwq/download_cr.png?dl=1");
        }
    }
}

const createTap = e =>{
    const taps = getElement(".nav nav-tabs")[0];
    const tap = document.createElement("li");
    tap.innerHTML = '<a data-toggle="tab" href="#sidepanel-rn">WME FixingMap</a>';
    taps.insertBefore(tap, taps.children[3].nextSibling);
    createWindow();
}

const createWindow = e =>{
    const wins = getElement(".tab-content")[0];
    const win = document.createElement("div");
    win.setAttribute("class", "tab-pane");
    win.setAttribute("id", "sidepanel-rn");
    win.setAttribute("style", "text-align: left;");

    const title = document.createElement("h2");
    title.setAttribute("style", "margin-bottom: 15px; border-bottom: 1px solid;");
    title.innerHTML = "WME FixingMap Plugin";
    win.appendChild(title);

    

    wins.insertBefore(win, wins.children[0]);

    NodeController();
    RoadController();

    const footer = document.createElement("div");
    footer.setAttribute("style", "margin-top: 20px; border-top: 1px solid; padding: 10px; text-align: center;");
    footer.innerHTML = "&copy;2018-2019 <a href='https://www.waze.com/ar/user/editor/sultan_alrefaei'>Sultan Alrefaei</a>";
    win.appendChild(footer);
}

const NodeController = element =>{
    //Title
    const title = document.createElement("h3");
    title.setAttribute("style", "margin-top: 10px; margin-bottom: 5px;");
    title.innerText = "Check Connection Nodes";
    getElement("#sidepanel-rn").appendChild(title);
    //Button Off
    const btnOff = document.createElement("button");
    btnOff.setAttribute("style", btn_rn);
    btnOff.setAttribute("id", "btnNodeOff");
    btnOff.style.backgroundColor = "#e91e63";
    btnOff.addEventListener("click", e =>{
        e.target.style.backgroundColor = "#e91e63";
        getElement("#btnNodeOn").style.backgroundColor = "#9E9E9E";
        stateNode = false;
        defaultNode();
    });
    btnOff.innerHTML = "Off";
    getElement("#sidepanel-rn").appendChild(btnOff);
    //Button On
    const btnOn = document.createElement("button");
    btnOn.setAttribute("style", btn_rn);
    btnOn.setAttribute("id", "btnNodeOn");
    btnOn.addEventListener("click", e =>{
        e.target.style.backgroundColor = "#4caf50";
        getElement("#btnNodeOff").style.backgroundColor = "#9E9E9E";
        stateNode = true;
        checkNodeIfConnection();
    });
    btnOn.innerHTML = "On";
    getElement("#sidepanel-rn").appendChild(btnOn);
}

const RoadController = element =>{
    //Title
    const title = document.createElement("h3");
    title.setAttribute("style", "margin-top: 10px; margin-bottom: 5px;");
    title.innerText = "Check If ROR";
    getElement("#sidepanel-rn").appendChild(title);
    //Button Off
    const btnOff = document.createElement("button");
    btnOff.setAttribute("style", btn_rn);
    btnOff.setAttribute("id", "btnRoadOff");
    btnOff.style.backgroundColor = "#e91e63";
    btnOff.addEventListener("click", e =>{
        e.target.style.backgroundColor = "#e91e63";
        getElement("#btnRoadOn").style.backgroundColor = "#9E9E9E";
        stateRoad = false;
    });
    btnOff.innerHTML = "Off";
    getElement("#sidepanel-rn").appendChild(btnOff);
    //Button On
    const btnOn = document.createElement("button");
    btnOn.setAttribute("style", btn_rn);
    btnOn.setAttribute("id", "btnRoadOn");
    btnOn.addEventListener("click", e =>{
        e.target.style.backgroundColor = "#4caf50";
        getElement("#btnRoadOff").style.backgroundColor = "#9E9E9E";
        stateRoad = true;
    });
    btnOn.innerHTML = "On";
    getElement("#sidepanel-rn").appendChild(btnOn);
}

const getElement = element =>{
    if (element.charAt(0) == "#"){
        element = element.replace("#", "");
        return document.getElementById(element) != null ? document.getElementById(element) : null;
    }else if (element.charAt(0) == "."){
        element = element.replace(".", "");
        return document.getElementsByClassName(element) != null ? document.getElementsByClassName(element) : null;
    }else{
        console.error("You must put # or .");
    }
}