// ==UserScript== // @name WME Check Road Name // @author buchet37 // @description This script make a Check for Roads naming // @namespace https://greasyfork.org/fr/scripts/3776-wme-check-road-name // @match https://world.waze.com/editor/* // @match https://*.waze.com/editor* // @match https://*.waze.com/*/editor/* // @match https://*.waze.com/*/editor* // @match https://world.waze.com/map-editor/* // @match https://world.waze.com/beta_editor* // @match https://www.waze.com/map-editor* // @connect https://docs.google.com/spreadsheets/d/ // @connect * // @sandbox javascript // @grant GM_xmlhttpRequest // @exclude https://www.waze.com/*user/editor/* // @version 4.7.6 // @downloadURL https://update.greasyfork.icu/scripts/3776/WME%20Check%20Road%20Name.user.js // @updateURL https://update.greasyfork.icu/scripts/3776/WME%20Check%20Road%20Name.meta.js // ==/UserScript== // Remerciements Myriades, seb-d59,DummyD2, Yopinet et tous les testeurs pour WME UR responses types /* global require */ /* global $ */ /* global OpenLayers */ /* global W */ /* global I18n */ var WME_CRN_version = "4.7.6"; var WME_CRN_country; var WME_CRN_Dictionary = []; var WME_CRN_MainCountry = ""; function waitForCountryTop () { var myWaze = unsafeWindow.W; if (myWaze && myWaze.model && myWaze.model.countries && myWaze.model.getTopCountry() && myWaze.model.getTopCountry().attributes) { var myCountryName = myWaze.model.getTopCountry().attributes.name; //alert ("On a recu le pays : " + myCountryname); var myCountryId = myWaze.model.getTopCountry().attributes.id; //alert ("On a recu le pays : " + myCountryname); var country = []; country[21] ={OTAN:' BEL ',main:'1mZF8KKMtJX1zYRoRNgweWfaczI9W6Nf9PDyKQkCB0ak',publiq:'1_Bx083h2mYD2Q4LlWO1JbAVc3uCKLZYVkDIwH4BqvvA',name:'Belgium'}; country[30] ={OTAN:' BRA ',main:'1MzMS2LThf8J_pwg_wfpNPoDbzU1H7WR1KbnuK2xcuUA',publiq:'1YM4yql0SVLJMkMqorVY52Qo9z49dE7qUvYKeH2APeVo',name:'Brazil'}; country[73] ={OTAN:' FRA ',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'France'}; country[74] ={OTAN:'FR-FG',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Guyane Française'}; country[75] ={OTAN:'FR-PF',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Polynésie Française'}; country[88] ={OTAN:'FR-GP',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Guadeloupe'}; country[141]={OTAN:'FR-MB',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Martinique',}; country[144]={OTAN:'FR-MA',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Mayotte'}; country[148]={OTAN:' MCO ',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Monaco',}; country[152]={OTAN:' MAR ',main:'1IAoaPWK2OwpVLFSvdNrJDa5SfQCmiI4u4BJ8UeobxFs',publiq:'1Y087xlOI-e_lUMZFnSTdRWvSLnQ_Bh3FZ8rKSVUs3aY',name:'Maroc'}; country[184]={OTAN:'FR-RE',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Réunion'}; country[209]={OTAN:'FR-PM',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Saint-Pierre et Miquelon'}; country[243]={OTAN:'FR-WF',main:'1fZNOmDQSYgAam6Lj3z9YpNFu0-Sb6AjAyFdy_dH-roA',publiq:'1T-UVFQtp5OrKqMZPRsfRBMohIAwdgNoWQcA6Ry4UEgA',name:'Wallis et Futuna'}; country[203]={OTAN:' ESP ',main:'1dR-DH0h-Ax_PP2buhrRj3qVdrqOOQ0HY-MZf4RfcBcI',publiq:'1lG7YjteuYpBvMzedHs4GcgtqjJuIaR3gKYhSlLZkO-E',name:'Spain'}; var french_country = [73,74,75,88,141,144,148,184,209,243]; if (country[myCountryId]) { unsafeWindow.mainDictionnaryKey = country[myCountryId].main; unsafeWindow.publicDictionnarykey = country[myCountryId].publiq; WME_CRN_country = country[myCountryId]; WME_CRN_country.frenchCountry = french_country;} else { alert ("WME Check Road Name Alert\n\nNo dictionnary for "+ myCountryName); unsafeWindow.WME_CRN_onload = "Error"; delete WME_CRN_1_mainDictionaryTxt; delete WME_CRN_1_publicDictionaryTxt; } GM_xmlhttpRequest({ //alert ("On démarre le chargement"); method: 'GET', url: 'https://docs.google.com/spreadsheets/d/' + unsafeWindow.mainDictionnaryKey +'/export?format=csv', // dictionaire principal headers: {"User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used. "Accept": "text/plain"}, // If not specified, browser defaults will be used. synchronous: false, onload: function (mainDictionary) { unsafeWindow.WME_CRN_1_mainDictionaryTxt = mainDictionary.responseText; } }); GM_xmlhttpRequest({ method: 'GET', url: 'https://docs.google.com/spreadsheets/d/' + unsafeWindow.publicDictionnarykey +'/export?format=csv', // dictionaire public headers: {"User-Agent": "Mozilla/5.0", "Accept": "text/plain"}, synchronous: false, onload: function (publicDictionary) { unsafeWindow.WME_CRN_1_publicDictionaryTxt = publicDictionary.responseText; } }); return myCountryId ; } else { setTimeout (function () {waitForCountryTop();}, 1000); //alert ("On attend le pays"); } } if ('undefined' == typeof WME_CRN_onload) { // le script n'est a pas encore chargé unsafeWindow.WME_CRN_onload = "In Progress"; unsafeWindow.WME_CRN_1_mainDictionaryTxt = "In Progress"; unsafeWindow.WME_CRN_1_publicDictionaryTxt = "In Progress"; var mainDictionnaryURL = '' ; var publicDictionnaryURL = '' ; waitForCountryTop(); } // ************* // ** INIT ** // ************* function CRN_bootstrap() { if (typeof unsafeWindow === "undefined") { unsafeWindow = (function () { var dummyElem = document.createElement('p'); dummyElem.setAttribute('onclick', 'return window;'); return dummyElem.onclick(); }) (); } /* begin running the code! */ // log("starting"); Check_Road_Name(); } function Check_Road_Name() { if ('undefined' != typeof require && W && W.map && W.model) { start_Road_Name(); } else { setTimeout(Check_Road_Name , 1000); } } function start_Road_Name() { WME_CRN_Dictionary = []; // déclaration Hors "loadFiles" pour compatibilité Chrome WME_CRN_MainCountry = ""; // ***************** COMPATIBILITY WITH NEW EDITOR *********** //var WazeActionCreateObject = require("Waze/Action/CreateObject"); // var WazeActionAddOrGetCity = require("Waze/Action/AddOrGetCity"); // var WazeActionAddOrGetStreet = require("Waze/Action/AddOrGetStreet"); var WazeActionMultiAction = require("Waze/Action/MultiAction"); var WazeActionUpdateObject = require("Waze/Action/UpdateObject"); var WazeActionAddAlternateStreet = require("Waze/Action/AddAlternateStreet"); var WazeActionUpdateFeatureAddress = require("Waze/Action/UpdateFeatureAddress"); //var WazeModelObjectType = require("Waze/Model/ObjectType"); // ***************************************************************** loadFiles (); function loadFiles () { // Passage en variable locales if (WME_CRN_1_mainDictionaryTxt != "In Progress" && WME_CRN_1_publicDictionaryTxt != "In Progress") { traiteDictionary(WME_CRN_1_mainDictionaryTxt,1); // main directory line 1 + traiteDictionary(WME_CRN_1_publicDictionaryTxt,2001); // public directory line 2001 + delete WME_CRN_1_mainDictionaryTxt; delete WME_CRN_1_publicDictionaryTxt; // supprime les variables d'import de fichiers WME_CRN_onload = "Done"; WME_CRN_MainCountry = W.model.getTopCountry().attributes.id; insertButton(); } else { setTimeout (function () {loadFiles();}, 1000); } } function traiteDictionary(texte,N_ligne) { var generic = texte.replace (/\t\t/g,"\t"); // supprime les doubles tabulation generic = generic.replace (/\r/g,"\n"); // remplace /r par /n generic = generic.replace (/\n\n\n/g,"\n"); // supprime triplon CR generic = generic.replace (/\n\n/g,"\n"); // supprime doublon CR var lignes = generic.split(/\n/); // split var error = []; for(var i = 0; i < lignes.length; i++) { //alert (lignes[i]); if (lignes[i].search('"') === 0) { // elimine les guillemets involontaires de l'import lignes[i] = lignes[i].replace (/^"/,''); lignes[i] = lignes[i].replace (/",/,','); } //alert (lignes[i]+' ' +lignes[i].search('//')); if (lignes[i].search('/') !== 0) {continue;} // si la ligne ne commence pas par / , on saute if (lignes[i].search('//') === 0) {continue;} // si la ligne commence par // , on saute //alert( lignes[i]); var pos = lignes[i].search("//"); if (pos != -1) {lignes[i] = lignes[i].substring(0,pos-1);} lignes[i] = lignes[i].replace (/"""/g,'"'); // Traitement des guillemets suite au CSV lignes[i] = lignes[i].replace (/""/g,'"'); // Traitement des guillemets suite au CSV //lignes[i] = lignes[i].replace (/^"/g,''); var inter1 = lignes[i].split(/,/); // Split with comma Char if (inter1.length <2) {continue;} // jump over if incorrect syntax if (inter1[0].substring(0,1) !="/") {inter1[0] = "/"+inter1[0]+"/";}//transform simple texte in regexp //inter1[1]="("+inter1[1].replace (/[ ]*$/g,"")+")"; inter1[1]=inter1[1].replace (/[ ]*$/g,""); var toverified = inter1[0].substring(1,inter1[0].lastIndexOf("/")); // extrait la partie entre / pour egexp var flag = inter1[0].substring(inter1[0].lastIndexOf("/")+1); // extrait le flag var correct = inter1[1].replace (/@/g,","); // replace à by comma if (correct == "()") {correct ='("")';} // interprete une chaine vide // WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified.replace (/@/g,",") , flags: flag.replace (/"/g,""), corrected : correct, fct : eval(correct)}); toverified = toverified.replace (/@/g,","); flag = flag.replace (/"/g,"") if (correct[0]=='"') { // c'est du texte correct = correct.slice (1,correct.length-1); WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : correct}); } if (correct.slice(0,8)== 'function') { // c'est une function switch (correct) { case 'function(a) {return(a.toUpperCase());}': WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aToUpperCase}); break; case 'function(a) {return(a.toLowerCase());}': WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aToLowercase}); break; case 'function(a,x,y) {return(x+y.toUpperCase());}': WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: axyToUpperCase}); break; case 'function(a,x,y) {return(x+y.toLowerCase());}': WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: axyToLowercase}); break; case 'function(a,x,y) {return(x.toUpperCase()+y.toLowerCase());}': WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: axToUpperCaseyToLowercase}); break; case "function(a) {return(a.split(/[eéèëê]/i).join('e'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplite}); break; case "function(a) {return(a.split(/[eéèëê]/i).join('é'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSpliteaigu}); break; case "function(a) {return(a.split(/[eéèëê]/i).join('è'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplitegrave}); break; case "function(a) {return(a.split(/[eéèëê]/i).join('ë'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplitetrema}); break; case "function(a) {return(a.split(/[eéèëê]/i).join('ê'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplitecirc}); break; case "function(a) {return(a.split(/[oöô]/i).join('o'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplito}); break; case "function(a) {return(a.split(/[oöô]/i).join('ö'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplitotrema}); break; case "function(a) {return(a.split(/[oöô]/i).join('ô'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplitocirc}); break; case "function(a) {return(a.split(/[iïî]/i).join('i'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSpliti}); break; case "function(a) {return(a.split(/[iïî]/i).join('ï'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSplititrema}); break; case "function(a) {return(a.split(/[iïî]/i).join('î'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct: aSpliticirc}); break; case "function(a) {return(a.split(/[uüûù]/).join('u'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitu}); break; case "function(a) {return(a.split(/[uüûù]/i).join('ü'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitutrema}); break; case "function(a) {return(a.split(/[uüûù]/i).join('û'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitucirc}); break; case "function(a) {return(a.split(/[uüûù]/i).join('ù'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitugrave}); break; case "function(a) {return(a.split(/[aàä]/).join('â'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitacirc}); break; case "function(a) {return(a.split(/[aàä]/).join('à'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitagrave}); break; case "function(a) {return(a.split(/c/i).join('ç'));}": WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified, flags: flag, fct : aSplitcced}); break; default: console.log('Function non comprise en ligne :'+i+N_ligne+ "---"+correct); error.push(correct); } } // WME_CRN_Dictionary.push({line :i+N_ligne, toVerify: toverified.replace (/@/g,",") , flags: flag.replace (/"/g,""), corrected : correct, fct : eval(correct)}); } } function aToUpperCase(a) {return (a.toUpperCase());} function aToLowercase(a) {return (a.toLowerCase());} function axyToUpperCase(a,x,y) {return (x+y.toUpperCase());} function axyToLowercase(a,x,y) {return (x+y.toLowerCase());} function axToUpperCaseyToLowercase(a,x,y) {return (x.toUpperCase()+y.toLowerCase());} function aSplite(a) {return(a.split(/[éeèëê]/i).join('e'));} function aSpliteaigu(a) {return(a.split(/[éeèëê]/i).join('é'));} function aSplitegrave(a) {return(a.split(/[éeèëê]/i).join('è'));} function aSplitetrema(a) {return(a.split(/[éeèëê]/i).join('ë'));} function aSplitecirc(a) {return(a.split(/[éeèëê]/i).join('ê'));} function aSplito(a) {return(a.split(/[oöô]/i).join('o'));} function aSplitotrema(a) {return(a.split(/[oöô]/i).join('ö'));} function aSplitocirc(a) {return(a.split(/[oöô]/i).join('ô'));} function aSpliti(a) {return(a.split(/[iïî]/i).join('i'));} function aSplititrema(a) {return(a.split(/[iïî]/i).join('ï'));} function aSpliticirc(a) {return(a.split(/[iïî]/i).join('î'));} function aSplitu(a) {return(a.split(/[uüûù]/i).join('u'));} function aSplitutrema(a) {return(a.split(/[uüûù]/i).join('ü'));} function aSplitucirc(a) {return(a.split(/[uüûù]/i).join('û'));} function aSplitugrave(a) {return(a.split(/[uüûù]/i).join('ù'));} function aSplitacirc(a) {return(a.split(/[aàä]/).join('â'));} function aSplitagrave(a) {return(a.split(/[aàä]/).join('à'));} function aSplitcced(a) {return(a.split(/c/i).join('ç'));} function insertButton() { if(document.getElementById('sidepanel-CRN') === null) { // **** Création structure nouvel onglet var cntEnt = document.createElement('section'); cntEnt.id = "WME_CRN_link"; cntEnt.style = "padding-top:2px; margin:2px; display:block;"; cntEnt.innerHTML = ''; cntEnt.innerHTML +='
Check Road Name ' + WME_CRN_version+ '
'; cntEnt.innerHTML +='
'+WME_CRN_country.OTAN+'
' var cntRename = document.createElement('section'); cntRename.id = "WME_CRN_rename"; cntRename.style = "padding-top:2px; margin:2px;display:block;"; cntRename.innerHTML = ''; cntRename.innerHTML +=''; cntRename.innerHTML +=''; cntRename.innerHTML +=''; cntRename.innerHTML += ''; cntRename.innerHTML += ''; cntRename.innerHTML += ''; cntRename.innerHTML += ''; var cntStrID = document.createElement('section'); cntStrID.id = "WME_CRN_StrID_title"; cntStrID.style = "padding-top:5px; margin:2px;margin-top:5px;border-top:1px solid skyblue;"; // cntStrID.innerHTML = ''; cntStrID.innerHTML = '' var cntChgAlt1 = document.createElement('section'); cntChgAlt1.id = "WME_CRN_ShowChangeToAltern"; cntChgAlt1.style = "padding-top:5px; margin:2px;margin-top:5px;border-top:1px solid skyblue;"; cntChgAlt1.innerHTML = '' // cntChgAlt1.innerHTML = ''; var cntLogs = document.createElement('section'); cntLogs.id = "WME_CRN_Comments_title"; cntLogs.style = "padding-top:5px; margin:2px;margin-top:5px;border-top:1px solid skyblue;"; cntLogs.innerHTML = ''; cntLogs.innerHTML +=''; cntLogs.innerHTML +=''; var WME_CRN_Menu = document.createElement('div'); WME_CRN_Menu.className = "tab-pane"; WME_CRN_Menu.style="padding:2px 2px 2px 5px; border-width:3px; border-style:double;border-color: SkyBlue; border-radius:10px"; WME_CRN_Menu.id = "sidepanel-CRN"; WME_CRN_Menu.appendChild(cntEnt); WME_CRN_Menu.appendChild(cntRename); WME_CRN_Menu.appendChild(cntStrID) WME_CRN_Menu.appendChild(cntChgAlt1); WME_CRN_Menu.appendChild(cntLogs); // **** Création nouvel onglet var sidebar = document.getElementById('sidebar'); var userTabs = document.getElementById('user-info'); var editPanel= document.getElementById('edit-panel'); var map = document.getElementById('map') if (sidebar.style.display == 'none' ||userTabs === null || map === null || editPanel=== null) {setTimeout (function () {insertButton();}, 500); return;} var navTabs = getElementsByClassName('nav-tabs', userTabs)[0]; var tabContent = getElementsByClassName('tab-content', userTabs)[0]; var newtab = document.createElement('li'); newtab.innerHTML = 'CRN'; navTabs.appendChild(newtab); tabContent.appendChild(WME_CRN_Menu); // **** Ajout Fonctions nouvel onglet document.getElementById ('WME_CRN_chk').onclick = function() {rename_Road2()}; document.getElementById ('WME_CRN_stop').onclick = function() {stop_check()}; document.getElementById ('WME_CRN_raz').onclick = function() {RAZ()}; document.getElementById ('WME_CRN_show_logs').onclick = function() {show_logs()}; document.getElementById ('WME_CRN_clear_logs').onclick = function() {clearLogs()}; document.getElementById ('WME_CRN_StreetID').onclick = function() {afficheSegProperties()}; document.getElementById ('WME_CRN_ChangeToAltern1').onclick = function() {ChAlternate()}; document.getElementById ('WME_CRN_TestRoadName').onclick = function() {saveLocalStorage()}; document.getElementById ('WME_CRN_TestAlternateRoadName').onclick = function() {saveLocalStorage()}; document.getElementById ('WME_CRN_TestPOIName').onclick = function() {saveLocalStorage()}; document.getElementById ('WME_CRN_TestAlternatePOIName').onclick = function() {saveLocalStorage()}; // ****Boite de dialogue CRN var myDialogBox = $ ('
'); var cnt000 = $('