WME Requests

Opens the Requests module with precompiled fields to submit an request

  1. // ==UserScript==
  2. // @name WME Requests
  3. // @namespace https://greasyfork.org/ru/scripts/5085-wme-requests
  4. // @description Opens the Requests module with precompiled fields to submit an request
  5. // @include https://*.waze.com/editor*
  6. // @include https://*.waze.com/*/editor*
  7. // @include https://*.waze.com/map-editor*
  8. // @include https://*.waze.com/beta_editor*
  9. // @include https://fias.nalog.ru/*
  10. // @grant none
  11. // @author skirda
  12. // @version 2.15.2.0
  13. // ==/UserScript==
  14.  
  15. var wmer_Version = '2.15.2.0';
  16.  
  17. if (location.hostname === "fias.nalog.ru")
  18. {
  19. if (window.location.search && window.location.search[0]==='?')
  20. {
  21. setTimeout(function(){
  22. var s=unescape(decodeURI(window.location.search.substr(1)));
  23. $("#MainForm").find(".rcbInput").val(s).change();
  24. $("#MainForm").find(".rcbArrowCell").find("A")[0].click();
  25. },1000);
  26. }
  27. return;
  28. }
  29.  
  30. var CL=new Array(
  31. {
  32. c:'Russia',
  33. cc:'ru',
  34. al:'ru_RU',
  35.  
  36. // Запрос на добавление населенного пункта
  37. f:'https://docs.google.com/forms/d/1ck0cCIV6vPy16YQZJvfmM0clOdAE2Z-kDsXn06ZwQ1s/viewform', // форма
  38. d:'https://docs.google.com/spreadsheets/d/1ddcW8EmNjojJp7EQ4AYPdfBqNWe28WqRaQ_RtkB8JAU', // таблица
  39. l:'https://script.google.com/macros/s/AKfycbzqA15-fy4g4StdRUmnuMj9z6rJ56gQPjCYpgCMni7h/exec', // Level5
  40. // WME Request (ответы)
  41. fr:'https://docs.google.com/forms/d/1QzvF3-lH8MuuEaSw0GA6LgLW62EiSHzQXBmG5-rQdIQ/viewform', // форма
  42. dr:'https://docs.google.com/spreadsheet/ccc?key=0AtcEFFDNcic4dEE2UFh5X0lDdlRZbno3YVFYUkg0Unc', // таблица
  43.  
  44. cs:'https://script.google.com/macros/s/AKfycbzqA15-fy4g4StdRUmnuMj9z6rJ56gQPjCYpgCMni7h/exec', // change state
  45.  
  46. ttst:'Marussia',
  47. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  48. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  49. },
  50. {
  51. c:'Belarus',
  52. cc:'by',
  53. al:'be_BY', // ru_BY
  54.  
  55. // Запрос на добавление населенного пункта
  56. f:'https://docs.google.com/forms/d/1a7g7ONWOIHfxr8ZEXKxRXUkIxFF7xFb-2uX4LlydWXo/viewform',
  57. d:'https://docs.google.com/spreadsheets/d/1uuRY8ib5h_8xMfpzgXG2N78foMtftUNkPzJxP56mDXI',
  58. l:'https://script.google.com/macros/s/AKfycbz8_xLefn_06nLRsfwnupviEEStCXfttg777KryBMnD/exec',
  59. // WME Request (ответы)
  60. fr:'https://docs.google.com/forms/d/1a9wXzngDV_KGoYZC65X_-xAUfcyA7vgftaEBC9aHAMM/viewform',
  61. dr:'https://docs.google.com/spreadsheets/d/1gge9vlSuDrxkzH0ubiRGcx3VOawYA-Hub7EZzP94siI',
  62.  
  63. cs: '', // change state
  64.  
  65. ttst:'Marussia',
  66. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  67. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  68. },
  69. {
  70. c:'Uzbekistan',
  71. cc:'uz',
  72. al:'uz_UZ', //
  73.  
  74. // Запрос на добавление населенного пункта
  75. f:'https://docs.google.com/forms/d/1wr3Bjkm1SKbThThdZ0ea80iriuoX9JJ4xRvutXcPGws/viewform', //
  76. d:'https://docs.google.com/spreadsheets/d/1sjniZzrQT5ygaZaMUzXKeoPFweASF7S7QPebNrHLo0Y', //
  77. l:'https://script.google.com/macros/s/AKfycbwKbjrauFor_XH4woPWrW9mkqvYCGzGXFoi6saWync/exec', //
  78. // WME Request (ответы)
  79. fr:'https://docs.google.com/forms/d/12oEAxVdrQZPUwHWK2AxKH0pIQwzG9UagRO0_ehRoaa4/viewform', //
  80. dr:'https://docs.google.com/spreadsheets/d/1wDYm7BKOpktL7MACucV-p94n-6M4HuyJy8HGntbumY4', //
  81.  
  82. cs: '', // change state
  83.  
  84. ttst:'Marussia',
  85. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  86. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  87. },
  88. {
  89. c:'Kazakhstan',
  90. cc:'kz',
  91. al:'kk_KZ', // ru_KZ
  92.  
  93. // Запрос на добавление населенного пункта
  94. f:'https://docs.google.com/forms/d/1zdqseCwkJqxkmb7w9geTcKI-VKA5dNl-QKvuIw1rObg/viewform',//
  95. d:'https://docs.google.com/spreadsheets/d/1rmmxyNOh7zSYU0U9v0nN0yx8ZOW9Vr83YepmC3vt8ms', //
  96. l:'https://script.google.com/macros/s/AKfycbyvmneTt9c8HuwuDevm5tGB8vBvkL9lHu9Bl_JWrNo/exec', //
  97. // WME Request (ответы)
  98. fr:'https://docs.google.com/forms/d/1Ap4i0pSbBc7OKfggSao8XmirjdlxQWIBEVQ1Cq1WYyQ/viewform', //
  99. dr:'https://docs.google.com/spreadsheets/d/1Vl1sXOCRK4eTCihfHJPB5oI2nDu9g7cVIu0gpcxI0-g', //
  100.  
  101. cs: '', // change state
  102.  
  103. ttst:'Marussia',
  104. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  105. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  106. },
  107. {
  108. c:'Ukraine',
  109. cc:'ua',// uk
  110. al:'uk_UA',
  111.  
  112. // Запрос на добавление населенного пункта
  113. f:'https://docs.google.com/forms/d/13BWQv9Kvwzii8IDyCBfztLqBAoQnI-dDLL4exTv4DOw/viewform',//
  114. d:'https://docs.google.com/spreadsheets/d/1C6P-VmSTR2KTS9LMIFZFQyf7r57ki9Mzi7B-HNwjBbM', //
  115. l:'https://script.google.com/macros/s/AKfycby2OUnHmGkbTNeJDBcXu4zZ6eyNngh6XHpkcU_tsoVSmHn-NzY/exec', //
  116. // WME Request (ответы)
  117. fr:'https://docs.google.com/forms/d/1VLcIJAFKrLumCINck6bWKJAXvHiJPriZKam3k309--k/viewform', //
  118. dr:'https://docs.google.com/spreadsheets/d/1_R8f_0_j57gU7EYKYBCaiIWi-vKWsPgtM-xuEBNGfks', //
  119.  
  120. cs: '', // change state
  121.  
  122. ttst:'Марічка',
  123. ttsd:'https://docs.google.com/spreadsheets/d/1B2xEnhZmiJa1rUAdrQa-kbBZANyU3uxBLWoNzlm3_4o', // TTS таблица UA
  124. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSepm_CwbQEyAIr-w8DqCXZsSgyEjSJIPG1AAigvOxwmXayADg/viewform' // TTS форма UA
  125. },
  126. {
  127. c:'Lithuania',
  128. cc:'lt',
  129. al:'lt_LT',
  130.  
  131. // Запрос на добавление населенного пункта
  132. f:'https://docs.google.com/forms/d/e/1FAIpQLSdiCSLrUX_mWGPzkCDzqmb_qvfY66Qgczz-AlvGN2ZLM7T5vg/viewform',//
  133. d:'https://docs.google.com/spreadsheets/d/1fKYvSYi2Hr8C8tiOVKr3IvpWvuwNtlm-kEBvsHSzljA', //
  134. l:'https://script.google.com/macros/s/AKfycbyt6joK8cqU3nLZwvi2DlFEGd9QjV0Sw5WbSuGrLjhK9fHBUO9Y/exec', //
  135. //https://script.google.com/macros/s/AKfycbztAHmVTR94oKtNo4pbx2ZCg30sjhYD59qMvQsKp1ob/dev
  136. // WME Request (ответы)
  137. fr:'https://docs.google.com/forms/d/e/1FAIpQLSf7karoWLOdSqthcdVpEG0VohJOZ8g33fvzRifMZMAun78nOg/viewform', //
  138. dr:'https://docs.google.com/spreadsheets/d/1TkvBW7Zc3thL9w44Hs42LVquhivibQwMrdEkCiLlSuM', //
  139.  
  140. cs: '', // change state
  141.  
  142. ttst:'Marussia',
  143. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  144. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  145. },
  146. {
  147. c:'Azerbaijan',
  148. cc:'az',
  149. al:'az-AZ',
  150.  
  151. // Запрос на добавление населенного пункта
  152. f:'https://docs.google.com/forms/d/e/1FAIpQLSceifAdBt5c58QOkuoTQUdi_ZJPG3LrM8ifb7veyBYinojD0A/viewform',//
  153. d:'https://docs.google.com/spreadsheets/d/1FFjON6qvEtpArEjEgy2oc11ua_q_GCddS6VQYQcQPWg', //
  154. l:'https://script.google.com/macros/s/AKfycbxgKPsxEwGviJnVBJyq53Uv8u__saiYNqnXhv0s54UOUL-L_utB/exec', //
  155. //https://script.google.com/macros/s/AKfycbztAHmVTR94oKtNo4pbx2ZCg30sjhYD59qMvQsKp1ob/dev
  156. // WME Request (ответы)
  157. fr:'https://docs.google.com/forms/d/e/1FAIpQLSdMzsss3xWRUtvtf_Uf58xoeSnKVQRq25mQ8QYeEP7pE8kWig/viewform', //
  158. dr:'https://docs.google.com/spreadsheets/d/18RYz0iX5AUBzn7Fm6GY7VwTctM0x_Tb9SjobJz6wiBQ', //
  159.  
  160. cs: '', // change state
  161.  
  162. ttst:'Marussia',
  163. ttsd:'https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI', // TTS таблица RU
  164. ttsf:'https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform' // TTS форма RU
  165. }
  166. );
  167.  
  168. //var wner_TTS_d="https://docs.google.com/spreadsheets/d/16rSWBWfRi5gXhywAlTGu6O3c3kH0B49ksp56hdh-xlI";
  169. //var wner_TTS_f="https://docs.google.com/forms/d/e/1FAIpQLSfUdwm1Jlv5h_tauxcWZRDnFSOv2QR8vzi2XcjWPe-TKnxzMQ/viewform";
  170.  
  171.  
  172. // через солько дней вернуть лок обратно
  173. var wmer_CountDays = 5;
  174. var wmer_UserCache = new Array();
  175. var wmer_LanguageRU = false;
  176. var wmer_Debug = false;
  177. var wmer_MousePos = '';
  178. var wmer_MapCenter = false;
  179. var wmer_AddCounty=false;
  180. var WMERequestEmail='';
  181. var WMERequestCountry=0;
  182. var wmer_SendDiscord = false;
  183.  
  184. /* helper function */
  185. function getElementsByClassName(classname, node)
  186. {
  187. if(!node)
  188. node = document.getElementsByTagName("body")[0];
  189. var a = [];
  190. var re = new RegExp('\\b' + classname + '\\b');
  191. var els = node.getElementsByTagName("*");
  192. for (var i=0,j=els.length; i<j; i++)
  193. if (re.test(els[i].className)) a.push(els[i]);
  194. return a;
  195. }
  196.  
  197.  
  198. function wmer_getUsername()
  199. {
  200. var thisUser = W.loginManager.user;
  201. if (thisUser === null)
  202. {
  203. alert(wmer_LanguageRU?'Невозможно получить имя текущего пользователя':'Nobody\'s logged in.');
  204. return "";
  205. }
  206. return W.loginManager.user.userName;
  207. }
  208.  
  209. function timeConverter(UNIX_timestamp)
  210. {
  211. var datetime = new Date();
  212. var mEpoch = parseInt(UNIX_timestamp);
  213. if (mEpoch<10000000000) mEpoch *= 1000;
  214. datetime.setTime(mEpoch);
  215. // !!! UTC !!!
  216. return datetime.getUTCFullYear()+"-"+('0' + (datetime.getUTCMonth() + 1)).slice(-2)+"-"+('0' + datetime.getUTCDate()).slice(-2)+"+"+('0' + datetime.getUTCHours()).slice(-2) + ':' + ('0' + datetime.getUTCMinutes()).slice(-2);
  217.  
  218. }
  219.  
  220. function GetWMESelected()
  221. {
  222. return W.selectionManager.getSelectedFeatures();
  223. }
  224.  
  225. function wmer_getCCSD(segment) // BUBBUB!!! need use "hasOwnProperty" or "in"
  226. {
  227. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'start wmer_getCCSD');
  228.  
  229. var oID="";
  230. var streetName="";
  231. var cityName="";
  232. var countryName="";
  233. var countryID="";
  234. var description="";
  235. var typeName= "";
  236. var stateID="";
  237. var stateName="";
  238. var cityID="";
  239. var userID="";
  240. var forumUserID="";
  241. var userName="";
  242. var updatedOn="";
  243. var poiaddress="";
  244.  
  245. try {
  246. typeName=segment.type;
  247. /*
  248. "segment"
  249. "venue"
  250. "node"
  251. "camera" typeName: "Speed camera"
  252. "bigJunction"
  253. */
  254. oID=segment.attributes.id;
  255. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': oID=' + oID);
  256.  
  257. if(segment.attributes.hasOwnProperty('updatedOn'))
  258. updatedOn=segment.attributes.updatedOn;
  259. else
  260. updatedOn=segment.attributes.createdOn;
  261.  
  262. if (segment.attributes.hasOwnProperty('primaryStreetID'))
  263. {
  264. //W.model.streets.get(GetWMESelected()[0].model.attributes.primaryStreetID).cityID
  265. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found street');
  266. var sID=segment.attributes.primaryStreetID;
  267. if (sID)
  268. {
  269. var streetsObj = W.model.streets.getObjectById(sID);
  270. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'typeof streetsObj='+(typeof streetsObj));
  271. if (typeof streetsObj !== "undefined")
  272. {
  273. cityID=streetsObj.cityID;
  274. streetName=streetsObj.name;
  275. }
  276. }
  277. }
  278. else if (typeName === "camera")
  279. {
  280. //GetWMESelected()[0].model.model.cities.additionalInfo[0].id
  281. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found camera');
  282. streetName=segment.typeName;
  283. description= "\n "+(wmer_LanguageRU?'Скорость':'Speed')+": "+segment.attributes.speed
  284. +"\n "+(wmer_LanguageRU?'Подтверждено':'Approved')+": "+segment.attributes.validated
  285. +"\n "+(wmer_LanguageRU?'Тип':'Type')+": "+I18n.translations[wmer_LanguageRU?"ru":window.I18n.currentLocale()].edit.camera.fields.type[segment.attributes.type];
  286. // +"\n "+(wmer_LanguageRU?'Азимут':'Azymuth')+": "+segment.attributes.azymuth
  287. //if(segment.attributes.hasOwnProperty('updatedOn'))
  288. cityID=segment.model.cities.additionalInfo[0].id;
  289. if (cityID == null)
  290. cityID="";
  291. }
  292. else if (typeName === "node")
  293. {
  294. //GetWMESelected()[0].model.segments.topCityID
  295. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found node');
  296. cityID=''+segment.model.segments.topCityID;
  297.  
  298. if (cityID == null)
  299. cityID="";
  300. description="\n count segment(s)="+segment.attributes.segIDs.length;
  301. }
  302. else if(typeName === "bigJunction")
  303. {
  304. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found bigJunction');
  305. cityID=''+segment.model.segments.topCityID;
  306. if (cityID == null)
  307. cityID="";
  308. description="\n count segment(s)="+segment.attributes.segIDs.length;
  309. }
  310. else // "venue"
  311. {
  312. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found POI ('+typeName+')');
  313. //W.model.streets.get(GetWMESelected()[0].attributes.streetID).cityID
  314. let sID=segment.attributes.streetID;
  315. if (sID == null)
  316. cityID="";
  317. else
  318. cityID=W.model.streets.getObjectById(sID).cityID;
  319.  
  320. if (sID == null)
  321. cityID="";
  322.  
  323. if (cityID !== "")
  324. {
  325. var cityObj=W.model.cities.getObjectById(cityID);
  326. if (typeof cityObj !== "undefined")
  327. {
  328. countryID=cityObj.getAttributes().countryID;
  329. stateID=cityObj.getAttributes().stateID;
  330. cityName=cityObj.getAttributes().name;
  331.  
  332. var stateObj=W.model.states.getObjectById(stateID);
  333. if (typeof stateObj !== "undefined")
  334. stateName=stateObj.getAttributes().name;
  335.  
  336. var countriesObj=W.model.countries.getObjectById(countryID);
  337. if(wmer_Debug) console.log(countriesObj);
  338. if (typeof countriesObj !== "undefined")
  339. countryName = countriesObj.name;
  340. }
  341. }
  342.  
  343. if (typeof GetWMESelected()[0].model.attributes.categories === "undefined")
  344. {
  345. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'categories=undefined');
  346. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'segment.attributes.description='+segment.attributes.description);
  347.  
  348. }
  349. else
  350. {
  351. var vcats=segment.attributes.categories;
  352. var arrvcats=[];
  353. for(var i=0; i < vcats.length; ++i)
  354. {
  355. //if(wmer_Debug) console.log("segment.attributes.categories["+i+"]='"+segment.attributes.categories[i]+"'")
  356. arrvcats.push(window.I18n.translations[wmer_LanguageRU?"ru":window.I18n.currentLocale()].venues.categories[vcats[i]]);
  357. //if(wmer_Debug) console.log("segment.attributes.categories["+i+"]='"+segment.attributes.categories[i]+"'")
  358. }
  359. description='\n '+(wmer_LanguageRU?'Категории':'Categories')+': '+(arrvcats.length > 0?arrvcats.join(';')+'.':'')+'\n ' + segment.attributes.description;
  360. //if(wmer_Debug) console.log(description)
  361. arrvcats=[];
  362.  
  363.  
  364. if (segment.attributes.categories.indexOf("GAS_STATION") != -1) // Gas Station
  365. {
  366. typeName="gas_station";
  367. description="\n "+(wmer_LanguageRU?'Брэнд':'Brand')+": "+segment.attributes.brand
  368. + "\n "+(wmer_LanguageRU?'Адрес':'Address')+": " + segment.attributes.address
  369. + "\n "+(wmer_LanguageRU?'Описание':'Description')+": " + segment.attributes.description;
  370. }
  371. }
  372.  
  373. if(segment.attributes.hasOwnProperty('streetID'))
  374. {
  375. var name=W.model.streets.getObjectById(segment.attributes.streetID).name;
  376. poiaddress+=name?name:"";
  377. }
  378. if(segment.attributes.hasOwnProperty('houseNumber'))
  379. {
  380. if(poiaddress.length > 0)
  381. poiaddress+= " ";
  382. poiaddress+=segment.attributes.houseNumber;
  383. }
  384. streetName=segment.attributes.name;
  385. }
  386.  
  387. if (!(/*typeName === "camera" || */typeName === "node" || cityID === "")) // BUGBUG!!!
  388. {
  389. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': cityID=' + cityID);
  390. let cityObj=W.model.cities.getObjectById(cityID);
  391. if (typeof cityObj !== "undefined")
  392. {
  393. countryID=cityObj.attributes.countryID;
  394. stateID=cityObj.attributes.stateID;
  395. cityName=cityObj.attributes.name;
  396.  
  397. let stateObj=W.model.states.getObjectById(stateID);
  398. if (typeof stateObj !== "undefined")
  399. stateName=stateObj.name;
  400.  
  401. let countriesObj=W.model.countries.getObjectById(countryID);
  402. if(wmer_Debug) console.log(countriesObj);
  403. if (typeof countriesObj !== "undefined")
  404. countryName = countriesObj.name;
  405. }
  406. }
  407.  
  408. if (!(typeName === "node"))
  409. {
  410. userID=segment.attributes.updatedBy;
  411. if (userID === null)
  412. userID=segment.attributes.createdBy;
  413.  
  414. if (userID==-1 || userID === null)
  415. {
  416. userID=segment.attributes.createdBy;
  417. if (userID==-1)
  418. {
  419. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'Do not PM Admin!');
  420. }
  421. }
  422.  
  423. userName=W.model.users.getObjectById(userID).userName;
  424. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'userName='+userName);
  425. }
  426. else
  427. userID="-1";
  428.  
  429. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'userID=' +userID);
  430.  
  431. }
  432. catch (err) {
  433. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': error['+err.columnNumber+','+err.lineNumber+']: ' +err.name);
  434. }
  435.  
  436. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'return from wmer_getCCSD');
  437. return {
  438. objid : oID,
  439. type : typeName,
  440. street : streetName,
  441. city : cityName,
  442. cityID : cityID,
  443. stateID : stateID,
  444. stateName : stateName,
  445. country : countryName,
  446. description : description,
  447. username : userName,
  448. userID : userID,
  449. forumuserID : forumUserID,
  450. updatedOn : updatedOn,
  451. poiaddress : poiaddress
  452. };
  453. }
  454.  
  455.  
  456. function wmer_userRank(segment)
  457. {
  458. var usrRank = 0;
  459. /*
  460. if (segment.attributes.lockRank)
  461. {
  462. var updatedBy = W.model.users.getObjectById(segment.attributes.updatedBy);
  463. return updatedBy != null ? updatedBy.rank : 0;
  464. }
  465. return 0;
  466. */
  467. if (GetWMESelected()[0].model.attributes.hasOwnProperty('lockRank'))
  468. return segment.attributes.lockRank;
  469. else
  470. return 0;
  471. }
  472.  
  473. //It returns the maximum lock level
  474. function wmer_GetLevel() {
  475. //attributes.rank dovrebbe essere il road rank
  476. var sel = GetWMESelected();
  477. var maxR = wmer_userRank(sel[0].model);
  478.  
  479. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() maxR='+maxR);
  480. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() sel.length='+sel.length);
  481.  
  482. for (let i = 1; i < sel.length; i++)
  483. {
  484. if (maxR == 5)
  485. {
  486. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() return 6');
  487. return 6;
  488. }
  489. var usrRank = wmer_userRank(sel[i].model);
  490. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() usrRank='+usrRank);
  491. if (usrRank > maxR) {
  492. maxR = usrRank;
  493. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() '+maxR);
  494. }
  495. }
  496. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_GetLevel() return [maxR + 1] = '+(maxR + 1));
  497. return maxR + 1;
  498. }
  499.  
  500. // получить данные имени НП у OSM
  501. function WmeR_GetCityFromOSM(ll,zoom,country)
  502. {
  503. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'WmeR_GetCityFromOSM([lat='+ll.lat+',lon='+ll.lon+'],'+zoom+',"'+country+'")');
  504. var cityName='';
  505. var country_code='';
  506. var address_json='';
  507.  
  508. if (country === '')
  509. {
  510. if (WMERequestCountry >= 0 && WMERequestCountry < CL.length)
  511. country=CL[WMERequestCountry].c;
  512. }
  513. zoom += 7;
  514. var url = 'https://nominatim.openstreetmap.org/reverse';
  515. var data = {
  516. "lat": ll.lat,
  517. "lon": ll.lon,
  518. "zoom": zoom,
  519. "format": "json",
  520. "addressdetails": 1,
  521. "countrycodes": (WMERequestCountry >= 0 && WMERequestCountry < CL.length?CL[WMERequestCountry].cc:"ru"),
  522. "accept-language": (WMERequestCountry >= 0 && WMERequestCountry < CL.length?CL[WMERequestCountry].al:"ru_RU")
  523. // https://www.fincher.org/Utilities/CountryLanguageList.shtml
  524. };
  525.  
  526. $.ajax({
  527. dataType: "json",
  528. cache: false,
  529. url: url,
  530. async: false,
  531. data: data,
  532. error: function() {
  533. },
  534. success: function(json) {
  535. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'WmeR_GetCityFromOSM(): json='+json);
  536. if (json.display_name !== undefined) {
  537. var li = '';
  538. if(wmer_Debug) console.dir(json);
  539. // json.address.country_code
  540. // json.address.state
  541. // json.address.region
  542. // json.address.city_district
  543. // json.address.suburb
  544. if (json.address.country_code !== undefined) {
  545. country_code=json.address.country_code;
  546. }
  547. address_json=json.address;
  548.  
  549. if (json.address.city !== undefined) {
  550. li = json.address.city;
  551. }
  552. else if (json.address.town !== undefined) {
  553. li = json.address.town;
  554. }
  555. else if (json.address.village !== undefined) {
  556. li = json.address.village;
  557. }
  558. else if (json.address.hamlet !== undefined) {
  559. li = json.address.hamlet;
  560. }
  561.  
  562. if (wmer_AddCounty && li.length > 0 && json.address.county !== undefined) {
  563. //console.log("country=",country)
  564. if (country==='Russia')
  565. {
  566. li += " (" + json.address.county.replace("район","").replace("область","").replace("городской округ","");
  567. //if (json.address.state !== undefined) {li += " / " + json.address.state; }
  568. //li += ")";
  569. li=li.trim();
  570. }
  571. else if (country==='Lithuania')
  572. {
  573. if(wmer_Debug) console.dir(json.address);
  574. // {village: "Sujainiai", county: "Paliepių seniūnija", state_district: "Raseinių rajono savivaldybė", state: "Kauno apskritis", country: "Lietuva", country_code: "lt"}
  575. li += ", " + json.address.county.replace("seniūnija","sen.").replace("rajono","r.").replace("savivaldybė","sav.").replace("apskritis","aps.");
  576. //Sujainiai, Paliepių seniūnija, Raseinių rajono savivaldybė, Kauno apskritis, Lietuva
  577. //if (json.address.state !== undefined) {li += " / " + json.address.state; }
  578. //li += ")";
  579. li=li.trim();
  580. }
  581. else
  582. {
  583. li += " (" + json.address.county.replace("район","р-н").replace("область","обл.").replace("городской округ","р-н");
  584. //if (json.address.state !== undefined) {li += " / " + json.address.state; }
  585. li += ")";
  586. }
  587. }
  588.  
  589. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'WmeR_GetCityFromOSM(): li='+li);
  590.  
  591. //$('#topbar-container .topbar .location-info-region .alt-location-info').html(alispan);
  592. cityName=li;
  593. }
  594. }
  595. });
  596.  
  597. return {cityName:cityName,country_code:country_code,address_json:address_json};
  598. }
  599.  
  600.  
  601. function PtInPoly(x, y, components)
  602. {
  603. let npol = components.length;
  604. let jj = npol - 1;
  605. var c = 0;
  606. for (var ii = 0; ii < npol;ii++)
  607. {
  608. if ((((components[ii].y<=y) && (y<components[jj].y)) || ((components[jj].y<=y) && (y<components[ii].y))) &&
  609. (x > (components[jj].x - components[ii].x) * (y - components[ii].y) / (components[jj].y - components[ii].y) + components[ii].x))
  610. {
  611. c = !c;
  612. }
  613. jj = ii;
  614. }
  615. return c;
  616. }
  617.  
  618. function checkPosKG(ll)
  619. {
  620. var p=[{x:33.545723,y:46.0000621},{x:33.5925865,y:46.0695387},{x:33.5961914,y:46.0775176},{x:33.5941315,y:46.0858525},{x:33.5924149,y:46.0875788},{x:33.5927582,y:46.1139437},{x:33.6037445,y:46.1303633},{x:33.610611,y:46.1339321},{x:33.6373901,y:46.1405933},{x:33.6178207,y:46.2135757},{x:33.6160183,y:46.2131599},{x:33.61413,y:46.2123878},{x:33.6128426,y:46.212863},{x:33.6133575,y:46.2138132},{x:33.6139584,y:46.2144666},{x:33.6172199,y:46.2153574},{x:33.6143875,y:46.2264623},{x:33.6461449,y:46.2293718},{x:33.6508656,y:46.2264623},{x:33.6551571,y:46.2247403},{x:33.6583328,y:46.2227807},{x:33.6642551,y:46.2217118},{x:33.674469,y:46.2151199},{x:33.6811638,y:46.2092993},{x:33.6857128,y:46.2060323},{x:33.6888027,y:46.2044879},{x:33.696785,y:46.2034186},{x:33.7084579,y:46.1999731},{x:33.7359238,y:46.1859512},{x:33.738842,y:46.1851788},{x:33.7409878,y:46.1850005},{x:33.7502575,y:46.188031},{x:33.7567806,y:46.191299},{x:33.7744617,y:46.1988444},{x:33.7851048,y:46.2014583},{x:33.7966919,y:46.2030028},{x:33.8113689,y:46.2035968},{x:33.8264751,y:46.2034186},{x:33.8388348,y:46.2018147},{x:33.8487053,y:46.1994979},{x:33.8618374,y:46.1941509},{x:33.9044952,y:46.1658034},{x:33.9177132,y:46.1585507},{x:33.9377975,y:46.150762},{x:33.961916,y:46.14321},{x:33.9851761,y:46.1343485},{x:34.0131569,y:46.1185845},{x:34.0213966,y:46.1143602},{x:34.0280914,y:46.1117422},{x:34.0356445,y:46.1101951},{x:34.0439701,y:46.109124},{x:34.0525532,y:46.1090645},{x:34.0565872,y:46.1099571},{x:34.0653419,y:46.1148362},{x:34.0695477,y:46.1162047},{x:34.0741825,y:46.1173946},{x:34.0812206,y:46.1172161},{x:34.091177,y:46.1156097},{x:34.1224194,y:46.1054941},{x:34.1291142,y:46.1015663},{x:34.1351223,y:46.0971621},{x:34.1409588,y:46.0913886},{x:34.1450787,y:46.0861502},{x:34.1502285,y:46.082102},{x:34.15658,y:46.078887},{x:34.1721153,y:46.0728734},{x:34.1776943,y:46.0693601},{x:34.1830158,y:46.0670377},{x:34.1866207,y:46.0660849},{x:34.1976929,y:46.0651916},{x:34.2121124,y:46.0627499},{x:34.2249012,y:46.0583426},{x:34.2339134,y:46.0557219},{x:34.247303,y:46.0530415},{x:34.2535686,y:46.0529224},{x:34.2642975,y:46.0543519},{x:34.2909908,y:46.0592956},{x:34.306097,y:46.0612014},{x:34.3175125,y:46.0614992},{x:34.3246365,y:46.061261},{x:34.3295288,y:46.0604272},{x:34.3405151,y:46.0576279},{x:34.3625736,y:46.0482165},{x:34.3809414,y:46.0369564},{x:34.39785,y:46.0214626},{x:34.4082355,y:46.0037586},{x:34.4124413,y:45.9900445},{x:34.4163036,y:45.9852736},{x:34.4254017,y:45.9760885},{x:34.4411945,y:45.9627255},{x:34.4570732,y:45.9520448},{x:34.4660854,y:45.9473303},{x:34.4773293,y:45.9433913},{x:34.4841957,y:45.942317},{x:34.4909763,y:45.9421976},{x:34.4974136,y:45.9429138},{x:34.5029068,y:45.94363},{x:34.5100307,y:45.9470319},{x:34.5228195,y:45.9550285},{x:34.5481396,y:45.9793691},{x:34.5511436,y:45.9867049},{x:34.5532036,y:45.9893289},{x:34.5601559,y:45.9929665},{x:34.5669365,y:45.9948747},{x:34.5747471,y:45.9955902},{x:34.5835018,y:45.9957691},{x:34.5995522,y:45.9945169},{x:34.6073627,y:45.9929069},{x:34.6297646,y:45.9859297},{x:34.6582603,y:45.97412},{x:34.6691608,y:45.968095},{x:34.7247791,y:45.9287071},{x:34.7531891,y:45.9100179},{x:34.8019409,y:45.902433},{x:34.7999668,y:45.8046917},{x:34.8609924,y:45.7945192},{x:34.8807335,y:45.7888935},{x:34.8975563,y:45.7824294},{x:34.9585819,y:45.7593198},{x:35.053854,y:45.787517},{x:36.7630005,y:45.8000844},{x:36.6778564,y:45.395316},{x:36.6081619,y:45.321013},{x:36.5068817,y:45.2903466},{x:36.529541,y:44.1664447},{x:31.9921875,y:44.1703849},{x:32.0361328,y:45.7253564},{x:33.545723,y:46.0000621}];
  621. if (PtInPoly(ll.lon, ll.lat, p))
  622. {
  623. return true;
  624. }
  625.  
  626. return false;
  627. }
  628.  
  629. function click_WMERequest() {
  630. var RenamePref="";
  631.  
  632. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'click_WMERequest()::Action: '+this.id);
  633. if (typeof W.selectionManager === "undefined")
  634. {
  635. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.selectionManager not found');
  636. return;
  637. }
  638. if (GetWMESelected().length == 0)
  639. {
  640. alert(wmer_LanguageRU?'Нет выделенных объектов':'No selected segments.');
  641. return;
  642. }
  643. if (GetWMESelected().length < 2 && this.id === 'wmerBtn_join')
  644. {
  645. alert(wmer_LanguageRU?'Вы должны выделить 2 сегмента':'You must select 2 segments.');
  646. return;
  647. }
  648.  
  649. var username = wmer_getUsername();
  650. var sccObj = wmer_getCCSD(GetWMESelected()[0].model);
  651. if(wmer_Debug) console.log("sccObj="+JSON.stringify(sccObj));
  652. if(sccObj.city && sccObj.city.length > 0)
  653. RenamePref="Rename: '" + sccObj.city + "' => '";
  654.  
  655. var lockLevel = wmer_GetLevel();
  656. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'lockLevel= '+lockLevel);
  657. if (lockLevel == 1 && this.id == 'wmerBtn_lock')
  658. {
  659. alert(wmer_LanguageRU?'Выбранные сегменты уже разблокированы':'Selected segments are already unlocked');
  660. return;
  661. }
  662.  
  663. var normalizedLevel=W.loginManager.user.normalizedLevel;
  664. //normalizedLevel=2;
  665. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'My level: '+normalizedLevel);
  666. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'Lock level: '+lockLevel);
  667.  
  668. if (lockLevel <= normalizedLevel && this.id == 'wmerBtn_lock') {
  669. alert(wmer_LanguageRU?'Выбранные сегменты имеют доступный вам уровень блокировки':'Selected segments have a lock level that is less or equal to yours');
  670. return;
  671. }
  672.  
  673. lockLevel=normalizedLevel;
  674.  
  675. var description='type: ' + sccObj.type + '\r' +
  676. 'country: '+ sccObj.country + '\r' +
  677. 'city: ' + sccObj.city + '\r' +
  678. 'street/name: ' + sccObj.street + '\r' +
  679. 'description: ' + sccObj.description;
  680.  
  681. description = description.replace(/%/g, '%25');
  682. description = description.replace(/\+/g, '%2B'); // +
  683. description = description.replace(' ', '%20'); // ' '
  684. description = description.replace(/\r\n/g, '\r'); // '\r\n'
  685. description = description.replace(/\r/g, '%0A'); // '\n'
  686. description = description.replace(/&/g, '%26');
  687. description = description.replace(/</g, '%3C');
  688. description = description.replace(/\>/g, '%3E');
  689. description = description.replace(/\?/g, '%3F');
  690. description = description.replace(/=/g, '%3D');
  691.  
  692. var permalink = wmer_generate_permalink();
  693.  
  694. // попытка центрировать...
  695. var urPos;
  696. if(!wmer_MapCenter) //???
  697. urPos=new OpenLayers.LonLat(W.map.getCenter().lon,W.map.getCenter().lat);
  698. else
  699. {
  700. var wmeSelected=GetWMESelected();
  701. urPos=new OpenLayers.LonLat(
  702. wmeSelected[0].geometry.bounds.left+(wmeSelected[0].geometry.bounds.right-wmeSelected[0].geometry.bounds.left)/2,
  703. wmeSelected[0].geometry.bounds.top-(wmeSelected[0].geometry.bounds.top-wmeSelected[0].geometry.bounds.bottom)/2
  704. );
  705. }
  706. urPos.transform(new OpenLayers.Projection("EPSG:900913"),new OpenLayers.Projection("EPSG:4326"));
  707.  
  708. var venues0='';
  709. if(getQueryString(permalink, 'venues') != -1)
  710. venues0="&venues=" + getQueryString(permalink, 'venues');
  711. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'venues0: '+venues0);
  712.  
  713. // https://www.waze.com/editor/?env=row&lon=36.11483&lat=53.96670&zoom=4&marker=yes
  714. var segments0='';
  715. if(getQueryString(permalink, 'segments') != -1)
  716. segments0="&segments=" + getQueryString(permalink, 'segments');
  717. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'segments0: '+segments0);
  718.  
  719.  
  720. var permalink5=permalink.split("&")[0] +
  721. "&zoom=" + parseInt(getQueryString(permalink, 'zoom')) +
  722. "&lon=" + urPos.lon +
  723. "&lat=" + urPos.lat +
  724. segments0 +
  725. venues0;
  726. var permalink50=permalink5;
  727.  
  728. function preparePermalink(s)
  729. {
  730. s = s.replace(/%/g, '%25'); //???
  731. s = s.replace(/&/g, '%26');
  732. s = s.replace(/\?/g, '%3F');
  733. s = s.replace(/=/g, '%3D');
  734. s = s.replace(/</g, '%3C');
  735. s = s.replace(/\>/g, '%3E');
  736. return s;
  737. }
  738.  
  739. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'permalink=' + permalink);
  740. var permalinkDiscord = permalink5;
  741. permalink = preparePermalink(permalink);
  742. permalink5 = preparePermalink(permalink5);
  743.  
  744. //You can get entry numbers in google stylesheet: "Answers->Get precompiled URL"
  745. var curDate=new Date();
  746. curDate.setDate(curDate.getDate() + wmer_CountDays);
  747.  
  748. var action="";
  749. switch(this.id)
  750. {
  751. case 'wmerBtn_lock':
  752. action='lock';
  753. break;
  754. case 'wmerBtn_join':
  755. action='join';
  756. break;
  757. case 'wmerBtn_dir':
  758. action='direction';
  759. break;
  760. case 'wmerBtn_turn':
  761. action='turn';
  762. break;
  763. case 'wmerBtn_closures':
  764. action='closures';
  765. break;
  766.  
  767. }
  768.  
  769. function zero2(d){
  770. if((""+d).length == 1)
  771. d="0" + "" + d;
  772. return d;
  773. }
  774.  
  775. // для автозаполнения имени НП в форме
  776. var osmName=WmeR_GetCityFromOSM(urPos,parseInt(getQueryString(permalink50, 'zoom')),sccObj.country);
  777.  
  778. var suffix="";
  779. var suffixCS="";
  780.  
  781. if(sccObj.country === '')
  782. {
  783. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': sccObj.country=""; work with osmName!!!');
  784. switch(osmName.country_code)
  785. {
  786. case 'ru': sccObj.country='Russia'; break;
  787. case 'by': sccObj.country='Belarus'; break;
  788. case 'uz': sccObj.country='Uzbekistan'; break;
  789. case 'kz': sccObj.country='Kazakhstan'; break;
  790. case 'ua': sccObj.country='Ukraine'; break;
  791. case 'lt': sccObj.country='Lithuania'; break;
  792. case 'az': sccObj.country='Azerbaijan'; break;
  793. }
  794. }
  795.  
  796. if (checkPosKG(urPos) && sccObj.country==='Ukraine')
  797. {
  798. sccObj.country='Russia';
  799. suffix=" / Крым";
  800. }
  801.  
  802.  
  803.  
  804. var idCL=(sccObj.country=='Russia'?0:(sccObj.country=='Belarus'?1:(sccObj.country=='Uzbekistan'?2:(sccObj.country==='Kazakhstan'?3:(sccObj.country==='Ukraine'?4:(sccObj.country==='Lithuania'?5:(sccObj.country==='Azerbaijan'?6:-1)))))));
  805. if(idCL == -1)
  806. {
  807. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': idCL = ' +idCL + ', sccObj.countryName='+sccObj.country);
  808. return;
  809. }
  810.  
  811. if(this.id === 'wmerBtn_tts')
  812. {
  813. /*
  814. entry.587168531=nik
  815. entry.846152130=email
  816. entry.1316827755=country
  817. entry.1780120881=Какое действие предпринять
  818. entry.722429754=Название сегмента как на карте
  819. entry.543004173=Сейчас произноситься так
  820. entry.495130616=...должно звучать так
  821. entry.1226154757=permalink
  822. entry.1360508522=remark
  823. */
  824. description='';
  825.  
  826. // TTS: always zoom = 4
  827. var urlTTS=CL[idCL].ttsf +
  828. '?entry.587168531=' + username +
  829. '&entry.846152130=' + WMERequestEmail +
  830. '&entry.1226154757=' + permalink5.replace(/zoom\%3D([0-9]+)\%26/,"zoom%3D4%26") +
  831. '&entry.1316827755=' + sccObj.country +
  832. //'&entry.1780120881=' + // Какое действие предпринять
  833. '&entry.722429754=' + sccObj.street + // Название сегмента как на карте
  834. '&entry.543004173=' + sccObj.street + // Сейчас произноситься так
  835. '&entry.495130616=' + sccObj.street + // ...должно звучать так
  836. '';
  837.  
  838. window.open(urlTTS, '_blank');
  839.  
  840. return;
  841. }
  842.  
  843.  
  844. if(wmer_Debug) console.log("--- osmName & sccObj ---");
  845. if(wmer_Debug) console.log(osmName);
  846. if(wmer_Debug) console.log(sccObj);
  847.  
  848. if (!sccObj.city || sccObj.city.length === 0)
  849. {
  850. sccObj.city=osmName.cityName;
  851. }
  852.  
  853. if (!sccObj.city || (typeof sccObj.city === "undefined"))
  854. sccObj.city='';
  855.  
  856. /*
  857. entry.1230839078 username
  858. entry.1797072526 e-mail
  859. entry.390417455 permalink
  860. entry.1508498769 Country
  861. entry.1856604039 Action
  862. entry.1939939237 Start Closures
  863. entry.1229617197 End Closures
  864. entry.1746680078 Причина перекрытия
  865. entry.1224334113 locklevel
  866. entry.571885954 EndUnlock
  867. entry.2082027069 Узел
  868. entry.259824358 Description
  869. */
  870. // !!!
  871. var url = CL[idCL].fr +
  872. '?entry.1230839078=' + username +
  873. '&entry.390417455=' + permalink5 +
  874. '&entry.1224334113=' + lockLevel +
  875. '&entry.1508498769=' + sccObj.country +
  876. '&entry.1856604039=' + action +
  877. '&entry.259824358=' + description + suffix +
  878. '&entry.1797072526=' + WMERequestEmail +
  879. '&entry.571885954='+curDate.getUTCFullYear()+'-'+zero2(curDate.getUTCMonth()+1)+'-'+zero2(curDate.getUTCDate()) +
  880. '';
  881.  
  882. // CL: always zoom = 4
  883. var urlCL = CL[idCL].f +
  884. '?entry.1109766685=' + username +
  885. '&entry.1785513403=' + WMERequestEmail +
  886. '&entry.1300384005=' + permalink5.replace(/zoom\%3D([0-9]+)\%26/,"zoom%3D4%26") +
  887. '&entry.1967623256=' + RenamePref+ sccObj.city + suffix + (RenamePref.length>0?"'":"") +
  888. '&entry.1393986642=' + sccObj.stateID +
  889. // '&entry.address_json=' + JSON.stringify(osmName.address_json) +
  890. '';
  891.  
  892. if (this.id == 'wmerA_cl') // доп проверка
  893. {
  894. if (sccObj.username === '' || sccObj.city === '' || sccObj.cityID === '')
  895. {
  896. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ALERT!!! ' + 'sccObj.username=',sccObj.username,"sccObj.city=",sccObj.city,"sccObj.cityID=",sccObj.cityID);
  897. alert(wmer_LanguageRU?"Внимание! Не полные данные (UserName, City или CityID). Сохранение не возможно.":"Attention! UserName, City or CityID ==> empty. Saving is not possible.");
  898. return;
  899. }
  900. }
  901.  
  902. var urlL5 = CL[idCL].l +
  903. '?func=saveLevel5' +
  904. '&p1=' + sccObj.username +
  905. '&p2=' + sccObj.city + suffix +
  906. '&p3=' + permalink5 +
  907. '&p4=' + timeConverter(sccObj.updatedOn) +
  908. '&p5=' + sccObj.cityID +
  909. '&p6=' + sccObj.stateID +
  910. '';
  911.  
  912.  
  913. var urlCS = null;
  914. if (CL[idCL].cs !== '')
  915. urlCS = CL[idCL].cs +
  916. '?p1=' + username +
  917. '&p2=' + WMERequestEmail +
  918. '&p3=' + permalink5 +
  919. '&p4=' + sccObj.city + ': изменить регион' +
  920. '&p5=' + sccObj.stateID +
  921. '&p6=' + sccObj.cityID +
  922. '';
  923.  
  924. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'urlL5=' + urlL5);
  925.  
  926. if(this.id === 'wmerA_cl')
  927. {
  928. if(sccObj.city === null || sccObj.city === '')
  929. {
  930. alert(wmer_LanguageRU?"Внимание! Имя НП пустое. Сохранение не возможно.":"Attention! The name of the city is empty. Saving is not possible.");
  931. return;
  932. }
  933. }
  934.  
  935. if(this.id === 'wmerCS_cl')
  936. {
  937. if(urlCS === null || sccObj.stateName === null || sccObj.stateName === '')
  938. {
  939. alert(wmer_LanguageRU?"Внимание! Имя Района пустое. Сохранение не возможно.":"Attention! The name of the state is empty. Saving is not possible.");
  940. return;
  941. }
  942. }
  943.  
  944. if (wmer_SendDiscord && !(this.id == 'wmerBtn_cl' || this.id == 'wmerA_cl' || this.id == 'wmerCS_cl'))
  945. {
  946. SendMessageToDiscord(1,"WME Request from @"+username+"\n"+action+" ("+sccObj.country+")"+": " +permalinkDiscord+"\nMax Lock Level = "+wmer_GetLevel());
  947. }
  948.  
  949. window.open(this.id == 'wmerBtn_cl'?urlCL:(this.id == 'wmerA_cl'?urlL5:(this.id == 'wmerCS_cl'?urlCS:url)), '_blank');
  950. }
  951.  
  952. function SendMessageToDiscord(chanel,msg)
  953. {
  954. var url;
  955. //https://discordapp.com/channels/378452611621191682/381408318624628738 - tts-marussia
  956. switch(chanel)
  957. {
  958. case 1:
  959. //url='https://discordapp.com/api/webhooks/379735358440472578/mmOSttTGc9lmURBGssDJICODzibzVLw8HKB70_BehPV0d_Pbi8luspMsWdz3VlEyczX9'; // lipetsk
  960. url='https://discordapp.com/api/webhooks/475921451791155231/oIKmOQCS0Ml--4diyS32tYDRC0AbiKu_OVoHdlz2C5b20lfKeB0TnARobWeH5KrXlKE0'; // Order
  961. break;
  962. default:
  963. url="";
  964. break;
  965. }
  966. if (url != "")
  967. {
  968. $.ajax({
  969. type: 'POST',
  970. url: url,
  971. contentType: 'application/json',
  972. data: JSON.stringify({
  973. username: 'WME Request Bot',
  974. avatar_url: 'https://cdn.discordapp.com/avatars/475921451791155231/597a85c13b8cb5707c34fef291f85832.png',
  975. content: msg,
  976. }),
  977. success: function (data) { },
  978. error: function (data) {
  979. if(wmer_Debug) console.log("from Discord:",data.responseText);
  980. }
  981. });
  982. }
  983. }
  984.  
  985.  
  986. function getQueryString(link, name)
  987. {
  988. if (link.indexOf( name + '=' ) <= 0)
  989. return -1;
  990. var pos = link.indexOf( name + '=' ) + name.length + 1;
  991. var len = link.substr(pos).indexOf('&');
  992. return (len == -1)?link.substr(pos):link.substr(pos,len);
  993. }
  994.  
  995. function wmer_generate_permalink() {
  996. var wcp=document.getElementsByClassName('WazeControlPermalink');
  997. for(var i=0; i < wcp.length; ++i)
  998. for (var j=0; j < wcp[i].getElementsByTagName('a').length;++j)
  999. {
  1000. var href=wcp[i].getElementsByTagName('a')[j].href;
  1001. if (href.indexOf(".waze.com/") > 0 && href.indexOf("/editor") > 0)
  1002. {
  1003. // kill "/ru/", kill "layers"
  1004. href=href.replace("/ru/","/").replace(/layers=([0-9]+)\&/,"") + "&marker=yes";
  1005. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'href=' + href);
  1006. return href;
  1007. }
  1008. }
  1009. return "";
  1010. }
  1011.  
  1012. function CreateID()
  1013. {
  1014. return 'WME-Request-' + wmer_Version.replace(/\./g,"-");
  1015. }
  1016.  
  1017.  
  1018. function wmer_insertButton(z)
  1019. {
  1020. //if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'wmer_insertButton()',GetWMESelected().length);
  1021. /*{
  1022. var permalink=wmer_generate_permalink();
  1023. var p = document.getElementsByClassName('WazeControlMousePosition')[0].lastChild.innerHTML.split(' ');
  1024. permalink=permalink.replace(/#/g, "").replace(/&lat=([0-9\.]+)/g, '&lat='+p[1]).replace(/&lon=([0-9\.]+)/g, '&lon='+p[0]);
  1025. }*/
  1026.  
  1027. // if(document.getElementById(CreateID()) != null)
  1028. // document.getElementById(CreateID()).setAttribute('style', 'display:'+(W.selectionManager && GetWMESelected().length == 0?'none':'')+';');
  1029.  
  1030. var wmeSelected=GetWMESelected();
  1031. if(wmeSelected.length <= 0)
  1032. return;
  1033.  
  1034. if (typeof wmeSelected[0].model === "undefined")
  1035. return;
  1036.  
  1037. switch(wmeSelected[0].model.type)
  1038. {
  1039. case "segment":
  1040. case "venue":
  1041. break;
  1042. case "city":
  1043. /*
  1044. attributes:
  1045. countryID: 186
  1046. englishName: null
  1047. id: 1501075
  1048. isEmpty: false
  1049. name: "Веселовский (Чертковский р-н)"
  1050. permissions: -1
  1051. rank: 4
  1052. stateID: 1839712
  1053. geometry:
  1054. bounds: null
  1055. id: "OpenLayers.Geometry.Point_910"
  1056. x: 4518527.665247766
  1057. y: 6312163.836996106
  1058. */
  1059. case "camera":
  1060. case "node":
  1061. case "bigJunction":
  1062. case "country":
  1063. case "houseNumber":
  1064. case "junction":
  1065. case "mapProblem":
  1066. case "roadClosure":
  1067. case "state":
  1068. default:
  1069. return;
  1070. }
  1071.  
  1072.  
  1073. //
  1074. if (wmeSelected[0].model.type === "venue")
  1075. {
  1076. var area_poi=document.getElementById('WME.PlaceNames-Square');
  1077. if(!area_poi)
  1078. {
  1079. var wcp=document.getElementsByClassName('additional-attributes list-unstyled side-panel-section');
  1080. if (wcp)
  1081. {
  1082. var li=document.createElement("LI");
  1083. li.setAttribute('id', 'WME.PlaceNames-Square');
  1084. wcp[0].appendChild(li);
  1085. area_poi=document.getElementById('WME.PlaceNames-Square');
  1086. }
  1087. }
  1088.  
  1089. if(area_poi)
  1090. {
  1091. var v_id=wmeSelected[0].model.attributes.id;
  1092. if (typeof W.model.venues.getObjectById(v_id).geometry.getGeodesicArea === "undefined")
  1093. area_poi.innerHTML="";
  1094. else
  1095. {
  1096. var square=W.model.venues.getObjectById(v_id).geometry.getGeodesicArea(W.map.getProjectionObject());
  1097. area_poi.style=(square < 650)?"color: red;":"color: black;";
  1098. area_poi.innerHTML="Площадь: " + square.toFixed(2) + " м&#178;";
  1099. }
  1100. }
  1101.  
  1102. }
  1103. /*
  1104. else if (wmeSelected[0].model.type === "camera") // camera-edit-general
  1105. {
  1106. var cam=document.getElementsByClassName('additional-attributes list-unstyled side-panel-section');
  1107. if (cam && cam.length > 0)
  1108. {
  1109. var camDate = wmeSelected[0].model.attributes.updatedOn;
  1110. if (!camDate)
  1111. camDate = wmeSelected[0].model.attributes.createdOn;
  1112. if (camDate)
  1113. {
  1114. var dateNow = new Date();
  1115. var age=Math.floor((dateNow.getTime() - camDate) / 86400000);
  1116. var li=document.createElement("LI");
  1117. li.setAttribute('id', 'WME.Age');
  1118. cam[0].appendChild(li);
  1119. camage=document.getElementById('WME.Age');
  1120. camage.innerHTML="Age: " + age + " day(s)";
  1121. }
  1122.  
  1123. }
  1124.  
  1125. }
  1126. */
  1127. //
  1128.  
  1129. var editPanelID='';
  1130. var disabled=false;
  1131. var disabledjoin=false;
  1132. var disabledLock=false;
  1133. var disabledPM=false;
  1134.  
  1135. if (document.getElementById('segment-edit-general') !== null)
  1136. {
  1137. editPanelID='segment-edit-general';
  1138. disabled=false;
  1139. disabledjoin=false;
  1140. disabledLock=false;
  1141. }
  1142. else if (document.getElementById('landmark-edit-general') !== null)
  1143. {
  1144. editPanelID='landmark-edit-general';
  1145. disabledLock=false;
  1146. disabledjoin=true;
  1147. disabled=true;
  1148. }
  1149. else if (document.getElementById('node-edit-general') !== null)
  1150. {
  1151. editPanelID='node-edit-general';
  1152. disabled=true;
  1153. disabledjoin=true;
  1154. disabledPM=true;
  1155. disabledLock=true;
  1156. }
  1157. else if (document.getElementById('edit-panel') !== null)
  1158. {
  1159. editPanelID='edit-panel';
  1160. disabled=true;
  1161. disabledjoin=true;
  1162. disabledLock=true;
  1163. }
  1164.  
  1165.  
  1166. var sccObj = wmer_getCCSD(wmeSelected[0].model);
  1167. if(wmer_Debug) console.dir(sccObj);
  1168.  
  1169. var urPos;
  1170. if(wmer_MapCenter)
  1171. urPos=new OpenLayers.LonLat(W.map.getCenter().lon,W.map.getCenter().lat);
  1172. else
  1173. {
  1174. urPos=new OpenLayers.LonLat(
  1175. wmeSelected[0].geometry.bounds.left+(wmeSelected[0].geometry.bounds.right-wmeSelected[0].geometry.bounds.left)/2,
  1176. wmeSelected[0].geometry.bounds.top-(wmeSelected[0].geometry.bounds.top-wmeSelected[0].geometry.bounds.bottom)/2
  1177. );
  1178. }
  1179. urPos.transform(new OpenLayers.Projection("EPSG:900913"),new OpenLayers.Projection("EPSG:4326"));
  1180.  
  1181. var osmName=WmeR_GetCityFromOSM(urPos,parseInt(getQueryString(wmer_generate_permalink(), 'zoom')),sccObj.country);
  1182. if(sccObj.country === '')
  1183. {
  1184. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': sccObj.country=""; work with osmName!!!');
  1185. // попытка центрировать...
  1186. //var osmName=WmeR_GetCityFromOSM(urPos,parseInt(getQueryString(wmer_generate_permalink(), 'zoom')),sccObj.country);
  1187. switch(osmName.country_code)
  1188. {
  1189. case 'ru': sccObj.country='Russia'; break;
  1190. case 'by': sccObj.country='Belarus'; break;
  1191. case 'uz': sccObj.country='Uzbekistan'; break;
  1192. case 'kz': sccObj.country='Kazakhstan'; break;
  1193. case 'ua': sccObj.country='Ukraine'; break;
  1194. case 'lt': sccObj.country='Lithuania'; break;
  1195. case 'az': sccObj.country='Azerbaijan'; break;
  1196. }
  1197. }
  1198. if (checkPosKG(urPos) && sccObj.country==='Ukraine')
  1199. {
  1200. sccObj.country='Russia';
  1201. }
  1202.  
  1203. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': sccObj.cityID=' + sccObj.cityID + ', sccObj.country='+sccObj.country);
  1204. var idCL=(sccObj.country=='Russia'?0:(sccObj.country=='Belarus'?1:(sccObj.country=='Uzbekistan'?2:(sccObj.country=='Kazakhstan'?3:(sccObj.country==='Ukraine'?4:(sccObj.country==='Lithuania'?5:(sccObj.country==='Azerbaijan'?6:-1)))))));
  1205. if(idCL == -1)
  1206. {
  1207. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': idCL = ' +idCL + ', sccObj.country='+sccObj.country);
  1208. idCL=0;
  1209. }
  1210.  
  1211. if(!document.getElementById(CreateID()))
  1212. {
  1213. // add new edit tab to left of the map
  1214. var srsCtrl = document.createElement('div');
  1215. srsCtrl.id = CreateID();
  1216.  
  1217. // inject new tab
  1218. var userTabs = document.getElementById('edit-panel');
  1219. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  1220. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': typeof navTabs=' + (typeof navTabs));
  1221. if (typeof navTabs !== "undefined")
  1222. {
  1223. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  1224.  
  1225. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': typeof tabContent=' + (typeof tabContent));
  1226. if (typeof tabContent !== "undefined")
  1227. {
  1228. let newtab = document.createElement('li');
  1229. newtab.innerHTML = '<a href="#' + CreateID() + '" id="pwmerequest" data-toggle="tab">'+(wmer_LanguageRU?'Запросы':'Requests')+'</a>';
  1230. navTabs.appendChild(newtab);
  1231.  
  1232. var padding="padding:5px 9px";
  1233. var html= /*'<hr>'+*/
  1234. '<div class="form-group">'+
  1235. '<h4>WME Requests <sup>' + wmer_Version + '</sup>&nbsp;<sub><a href="https://greasyfork.org/ru/scripts/5085-wme-requests" title="Link" target="_blank"><span class="fa fa-external-link"></span></a></sub></h4>'+
  1236. '<form class="attributes-form side-panel-section" action="javascript:return false;">'+
  1237. '<div class="controls-container">';
  1238.  
  1239. // --- Общее ---
  1240. html += ''+
  1241. '<div class="form-group">'+
  1242. '<label class="control-label">' + (wmer_LanguageRU?'Общие':'Common') +'</label>' +
  1243. '<label><a href="' + CL[idCL].dr + '" id="wmerA_dr" target="_gdocRequest" title="' + sccObj.country + '">' + (wmer_LanguageRU?'Таблица':'Table') +'</a></label> | '+
  1244. '<label><a href="https://www.waze.com/forum/viewtopic.php?p=662218#p662218" title="City Lock ' + wmer_Version + '" target="_blank">' + (wmer_LanguageRU?'О проекте':'About') +'</a></label></br>'+
  1245. '<button id="wmerBtn_lock" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1246. (wmer_LanguageRU?'Отправить запрос на изменение уровня блокировки объектов':'Send a request to lock/unlock segment(s)')+
  1247. '"><i class="fa fa-unlock"></i>&nbsp;Lock</button>&nbsp;' +
  1248. '<button id="wmerBtn_join" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1249. (wmer_LanguageRU?'Отправить запрос на присоединение сегментов':'Send a request to join several segments')+
  1250. '"><i class="fa fa-cogs"></i>&nbsp;Join</button>&nbsp;' +
  1251. '<button id="wmerBtn_dir" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1252. (wmer_LanguageRU?'Отправить запрос на изменение направления движения сегментов':'Send a request to change the direction of segment(s)')+
  1253. '"><i class="fa fa-random"></i>&nbsp;Dir</button>&nbsp;' +
  1254. '<button id="wmerBtn_turn" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1255. (wmer_LanguageRU?'Отправить запрос на изменение разрешения поворотов':'Send a request to change the turn restriction.')+
  1256. '"><i class="fa fa-arrows-alt"></i>&nbsp;Turn</button>&nbsp;' +
  1257. '<button id="wmerBtn_closures" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1258. (wmer_LanguageRU?'Отправить запрос на изменение перекрытие сегментов':'Send a request to change the Real Time Closures.')+
  1259. '"><i class="fa fa-calendar"></i>&nbsp;Closures</button>' +
  1260. '<div class="controls-container">' +
  1261. '<input name="wmerChk_discord" value="" id="wmerChk_discord" type="checkbox"><label for="wmerChk_discord" title="'+(wmer_LanguageRU?'Дублировать запрос в Discord':'Send to Discord')+'">Discord</label><br>' +
  1262. '</div>'
  1263. '</div></div>';
  1264.  
  1265. // --- CityLock ---
  1266. html += ''+
  1267. '<div class="form-group">'+
  1268. '<label class="control-label">' + (wmer_LanguageRU?'CityLock':'CityLock') +'</label>' +
  1269. '<div class="controls-container">' +
  1270. '<label><a href="' + CL[idCL].d + '" id="wmerA_d" target="_gdocRequest" title="' + sccObj.country + '">' + (wmer_LanguageRU?'Таблица':'Table') +'</a></label> | '+
  1271. '<label><a href="https://www.waze.com/forum/viewtopic.php?f=787&t=105793" title="City Lock ' + wmer_Version + '" target="_blank">' + (wmer_LanguageRU?'О проекте':'About') +'</a></label></br>'+
  1272. '<button id="wmerBtn_cl" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1273. (wmer_LanguageRU?'Отправить запрос на изменение наименования населенного пункта':'Send a request to CityLock')+
  1274. '"><i class="fa fa-home"></i>&nbsp;City</button>'+
  1275. '&nbsp;<span id="wmerChangeState0"></span>' +
  1276. '&nbsp;<span id="wmerCitySave0"></span></br>' +
  1277. '<label><span id="wmerCityID"></span><br>'+
  1278. '<span id="wmerStateID"></span></label>'+
  1279. '<div class="controls-container">' +
  1280. '<label>Language from OSM:</label>' +
  1281. '<select class="form-control" id="wmerEdt_country" title="Для запросов по созданию/изменению НП принудительно задавать язык получемых данных из OSM">';
  1282.  
  1283. for(var cli=0; cli < CL.length; ++cli)
  1284. html+='<option value="'+cli+'">'+CL[cli].c+'</option>';
  1285.  
  1286. html += ''+
  1287. '</select>'+
  1288. '</div>'+
  1289. '<div class="controls-container" style="display:none">' +
  1290. '<input name="wmerChk_county" value="" id="wmerChk_county" type="checkbox"><label for="wmerChk_county" title="'+(wmer_LanguageRU?'Добавлять РАЙОН в название НП':'Adding DISTRICT in the name of the locality')+'">&nbsp;'+(wmer_LanguageRU?'Добавлять район':'Add District')+'</label><br>' +
  1291. '</div>' +
  1292. //'</br><label><span id="wmerLatLon"></span></label>'+
  1293. '</div></div>';
  1294.  
  1295. // --- TTS ---
  1296. html += ''+
  1297. '<div class="form-group">'+
  1298. '<label class="control-label">TTS Requests</label>' +
  1299. '<div class="controls-container">' +
  1300. '<label><a href="' + CL[idCL].ttsd + '" id="wmerTTS_d" target="_gdocRequest" title="TTS '+CL[idCL].ttst +'">' + (wmer_LanguageRU?'Таблица':'Table') +'</a></label> | '+
  1301. '<label><a href="https://www.waze.com/forum/viewtopic.php?f=785&t=148400" title="'+CL[idCL].ttst +' - новый TTS-голос" target="_blank">' + (wmer_LanguageRU?'О проекте':'About') +'</a></label></br>'+
  1302. //'<select class="form-control" id="wmerEdt_TTSSelect" title="">'+
  1303. //'<option value="Marussia">Маруся</option>'+
  1304. //'<option value="Марічка">Марічка</option>'+
  1305. //'</select>'+
  1306. '<button id="wmerBtn_tts" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1307. (wmer_LanguageRU?'Отправить запрос по проблеме произношения или сокращения в Waze TTS '+CL[idCL].ttst:'Send a request to the pronunciation problem or reduction in Waze TTS '+CL[idCL].ttst)+
  1308. '"><i class="fa fa-volume-up"></i>&nbsp;TTS</button></br>' +
  1309. '</div></div>';
  1310.  
  1311. // --- Прочее ---
  1312. html += ''+
  1313. '<div class="form-group">'+
  1314. '<label class="control-label">' + (wmer_LanguageRU?'Прочее':'Other') +'</label>' +
  1315. '<div class="controls-container">' +
  1316. '<button id="wmerBtn_pm" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1317. (wmer_LanguageRU?'Отправить приватное сообщение в форум авторам выделенных объектов':'Send (in forum) a Private Message to the author of the segment')+
  1318. '"><li class="fa fa-envelope"></li>&nbsp;PM</button>'+
  1319. '</div></div>';
  1320.  
  1321.  
  1322.  
  1323. // --- Настройки ---
  1324. html += ''+
  1325. '<div class="form-group">' +
  1326. '<label class="control-label">' + (wmer_LanguageRU?'Настройки':'Config') +'</label>';
  1327.  
  1328. html += ''+
  1329. '<div class="controls-container">' +
  1330. '<label>E-mail:' +
  1331. '<input title="' + (wmer_LanguageRU?'Ваш e-mail адрес':'Your e-mail address') +'" type="text" class="form-control" autocomplete="off" id="wmerEdt_email" name="wmerEdt_email" value="" size="15"/></label><br>' +
  1332. '</div>'+
  1333. '<div class="controls-container">' +
  1334. '<input name="wmerChk_mapcenter" value="" id="wmerChk_mapcenter" type="checkbox"><label for="wmerChk_mapcenter" title="'+(wmer_LanguageRU?'Брать координаты центра карты':'Брать координаты центра карты')+'">Map Center</label>' +
  1335. '</div>'+
  1336. '<div class="controls-container">' +
  1337. '<input name="wmerEdt_lang" value="" id="wmerEdt_lang" type="checkbox"><label for="wmerEdt_lang" title="'+(wmer_LanguageRU?'Принудительно использовать русскоязычный интерфейс для WME Request':'Forced to use Russian-language interface for WM Request')+'">Russian UI</label>' +
  1338. '</div>'+
  1339. '<div class="controls-container">' +
  1340. '<input name="wmerChk_debug" value="" id="wmerChk_debug" type="checkbox"><label for="wmerChk_debug" title="'+(wmer_LanguageRU?'Включить логирование':'Enable debug script')+'">Debug script</label><br>' +
  1341. '</div>';
  1342.  
  1343. html += ''+
  1344. '</div>' +
  1345. '</form>'+
  1346. '</div>' +
  1347. '';
  1348.  
  1349. srsCtrl.innerHTML = html;
  1350. //srsCtrl.id = "sidepanel-wmerequest";
  1351. srsCtrl.className = "tab-pane";
  1352. tabContent.appendChild(srsCtrl);
  1353. }
  1354. else
  1355. srsCtrl.id='';
  1356. }
  1357. else
  1358. srsCtrl.id='';
  1359. //http://www.earthtools.org/sun/51.65500265464235/39.18297673378902/22/1/99/0
  1360. //document.getElementById(editPanelID).appendChild(srsCtrl);
  1361.  
  1362. if(srsCtrl.id !== '')
  1363. {
  1364. document.getElementById('wmerBtn_lock').onclick = click_WMERequest;
  1365. document.getElementById('wmerBtn_dir').onclick = click_WMERequest;
  1366. document.getElementById('wmerBtn_turn').onclick = click_WMERequest;
  1367. document.getElementById('wmerBtn_closures').onclick = click_WMERequest;
  1368. document.getElementById('wmerBtn_join').onclick = click_WMERequest;
  1369. document.getElementById('wmerBtn_pm').onclick = click_submitPMForm;
  1370. document.getElementById('wmerBtn_cl').onclick = click_WMERequest;
  1371. document.getElementById('wmerBtn_tts').onclick = click_WMERequest;
  1372. }
  1373.  
  1374. //var permalink=wmer_generate_permalink();
  1375. //var p = document.getElementsByClassName('WazeControlMousePosition')[0].innerHTML.replace(' ', '').split(',');
  1376. //var p = document.getElementsByClassName('WazeControlMousePosition')[0].lastChild.innerHTML.split(' ');
  1377. //permalink=permalink.replace(/#/g, "").replace(/&lat=([0-9\.]+)/g, '&lat='+p[1]).replace(/&lon=([0-9\.]+)/g, '&lon='+p[0]);
  1378. /*
  1379. if (typeof GetWMESelected()[0].geometry.x !== "undefined")
  1380. {
  1381. // корректировка пермалинка для камеры, жанкшина и Place (point)
  1382. var urPos=new OpenLayers.LonLat(GetWMESelected()[0].geometry.x,GetWMESelected()[0].geometry.y);
  1383. urPos.transform(new OpenLayers.Projection("EPSG:900913"),new OpenLayers.Projection("EPSG:4326")); // {lon, lat}
  1384. permalink=permalink.replace(/#/g, "").replace(/&lat=([0-9\.]+)/g, '&lat='+urPos.lat).replace(/&lon=([0-9\.]+)/g, '&lon='+urPos.lon);
  1385. }
  1386. */
  1387. //document.getElementById('wmerCityID').innerHTML='<small><a href="'+permalink+'">cityID: '+sccObj.cityID+'</a></small>';
  1388. //document.getElementById('wmerCityID').innerHTML='<small>cityID: '+sccObj.cityID+'</small>';
  1389. /*
  1390. if(W.loginManager.user.rank >= 4)
  1391. {
  1392. document.getElementById('wmerCityID').innerHTML+='&nbsp;(<small><a style="cursor: pointer" title="Save the name of the new city in the Google Table" id="wmerA_cl">save</a></small>)';
  1393. document.getElementById('wmerA_cl').onclick = click_WMERequest;
  1394. }
  1395. */
  1396.  
  1397. //document.getElementById('wmerLatLon').innerHTML='<small>'+p[0]+','+p[1]+'</a></small>';
  1398.  
  1399. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'initialised');
  1400. }
  1401.  
  1402. if(document.getElementById(CreateID()) != null)
  1403. {
  1404.  
  1405. // ********************
  1406. if(document.getElementById('wmerA_dr'))
  1407. {
  1408. document.getElementById('wmerA_dr').href=CL[idCL].dr;
  1409. document.getElementById('wmerA_dr').title=sccObj.country;
  1410. }
  1411. if(document.getElementById('wmerA_d'))
  1412. {
  1413. document.getElementById('wmerA_d').href=CL[idCL].d;
  1414. document.getElementById('wmerA_d').title=sccObj.country;
  1415. }
  1416.  
  1417. // ********************
  1418. if(document.getElementById('wmerCityID'))
  1419. {
  1420. //if(wmer_Debug) console.log("osmName.cityName=",osmName.cityName)
  1421. if (sccObj.country === 'Russia') // need script!
  1422. //document.getElementById('wmerCityID').innerHTML='<small>cityID: <a href="http://fias.nalog.ru/?'+osmName.cityName+'" target="_blank">'+sccObj.cityID+'</a></small>';
  1423. document.getElementById('wmerCityID').innerHTML='<small><a href="http://fias.nalog.ru/?'+sccObj.city+' ('+sccObj.stateName+'" title="Проверить имя в fias" target="_blank">cityID:</a> <span id="__clpCI" style="cursor:pointer;" title="Копировать CityID">'+sccObj.cityID+'</span></small>';
  1424. else
  1425. document.getElementById('wmerCityID').innerHTML='<small>cityID: <span id="__clpCI" style="cursor:pointer;" title="Копировать cityID">'+sccObj.cityID+'</span></small>';
  1426. document.getElementById('__clpCI').onclick=function(){clipboard.copy(this.innerText);}
  1427. }
  1428. if(document.getElementById('wmerStateID'))
  1429. {
  1430. document.getElementById('wmerStateID').innerHTML='<small>stateID: <span id="__clpSI" style="cursor:pointer;" title="Копировать stateID">'+sccObj.stateID+'</span></small>';
  1431. document.getElementById('__clpSI').onclick=function(){clipboard.copy(this.innerText);}
  1432. }
  1433.  
  1434.  
  1435. // ********************
  1436. // config e-mail
  1437. if(document.getElementById('wmerEdt_email'))
  1438. {
  1439. document.getElementById('wmerEdt_email').value=WMERequestEmail;
  1440. document.getElementById('wmerEdt_email').onchange=function(){WMERequestEmail=this.value;localStorage.setItem('WMERequestEmail', WMERequestEmail);}
  1441. }
  1442.  
  1443. if(document.getElementById('wmerEdt_country'))
  1444. {
  1445. document.getElementById("wmerEdt_country").selectedIndex = WMERequestCountry;
  1446. document.getElementById("wmerEdt_country").onchange = function(){WMERequestCountry=parseInt(this.value);localStorage.setItem("WMERequestCountry",WMERequestCountry);};
  1447. }
  1448.  
  1449. // ********************
  1450. // config language
  1451. if (document.getElementById('wmerEdt_lang'))
  1452. {
  1453. var WMELanguageRU=localStorage.getItem("WMELanguageRU");
  1454. if (WMELanguageRU)
  1455. wmer_LanguageRU=WMELanguageRU === "1"?true:false;
  1456. document.getElementById('wmerEdt_lang').checked=wmer_LanguageRU;
  1457. document.getElementById('wmerEdt_lang').onchange=function(){wmer_LanguageRU=this.checked;localStorage.setItem('WMELanguageRU', wmer_LanguageRU?"1":"0");}
  1458. }
  1459.  
  1460. // ********************
  1461. // config debug
  1462. document.getElementById('wmerChk_debug').checked=wmer_Debug;
  1463. document.getElementById('wmerChk_debug').onchange=function(){wmer_Debug=this.checked;localStorage.setItem('wmer_Debug', wmer_Debug?"1":"0");}
  1464.  
  1465. // config send to discord
  1466. document.getElementById('wmerChk_discord').checked=wmer_SendDiscord;
  1467. document.getElementById('wmerChk_discord').onchange=function(){wmer_SendDiscord=this.checked;localStorage.setItem('wmer_SendDiscord', wmer_SendDiscord?"1":"0");}
  1468.  
  1469. // config map center
  1470. document.getElementById('wmerChk_mapcenter').checked=wmer_MapCenter;
  1471. document.getElementById('wmerChk_mapcenter').onchange=function(){wmer_MapCenter=this.checked;localStorage.setItem('WMERequestMapCenter', wmer_MapCenter?"1":"0");}
  1472.  
  1473. // config AddCounty
  1474. document.getElementById('wmerChk_county').checked=wmer_AddCounty;
  1475. document.getElementById('wmerChk_county').onchange=function(){wmer_AddCounty=this.checked;localStorage.setItem('WMERequestAddCounty', wmer_AddCounty?"1":"0");}
  1476.  
  1477.  
  1478. // ********************
  1479. if(sccObj.country==='Russia')
  1480. {
  1481. document.getElementById('wmerChangeState0').innerHTML=
  1482. '<button id="wmerCS_cl" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1483. (wmer_LanguageRU?'Изменить район':'Change State')+
  1484. '"><i class="fa fa-map-marker"></i>&nbsp;State</button>';
  1485.  
  1486. document.getElementById('wmerCS_cl').onclick = click_WMERequest;
  1487. }
  1488.  
  1489. if(W.loginManager.user.rank >= 4 || (sccObj.country=='Belarus' && W.loginManager.user.rank >= 3)) // ??? Uzbekistan ???
  1490. {
  1491. document.getElementById('wmerCitySave0').innerHTML=
  1492. '<button id="wmerA_cl" class="btn btn-default" style="font-size:9px;'+padding+'" title="'+
  1493. (wmer_LanguageRU?'Сохранить имя нового НП в Google-таблице':'Save the name of the new city in the Google Table')+
  1494. '"><i class="fa fa-floppy-o"></i>&nbsp;Save</button>';
  1495.  
  1496. //document.getElementById('wmerCityID').innerHTML+='&nbsp;(<small><a style="cursor: pointer" title="Save the name of the new city in the Google Table" id="wmerA_cl">save</a></small>)';
  1497. document.getElementById('wmerA_cl').onclick = click_WMERequest;
  1498. }
  1499. }
  1500.  
  1501. if(document.getElementById(CreateID()) != null)
  1502. {
  1503. document.getElementById('wmerBtn_lock').disabled=disabledLock;
  1504. document.getElementById('wmerBtn_dir').disabled=disabled;
  1505. document.getElementById('wmerBtn_turn').disabled=disabled;
  1506. document.getElementById('wmerBtn_closures').disabled=disabled;
  1507. document.getElementById('wmerBtn_join').disabled=disabled;
  1508. document.getElementById('wmerBtn_pm').disabled=disabledPM;
  1509. document.getElementById('wmerBtn_cl').disabled=disabled;
  1510. //document.getElementById('wmerBtn_tts').disabled=disabled;
  1511. if(document.getElementById('wmerA_cl'))
  1512. document.getElementById('wmerA_cl').disabled=disabled;
  1513. if(document.getElementById('wmerCS_cl'))
  1514. document.getElementById('wmerCS_cl').disabled=disabled;
  1515.  
  1516. }
  1517. }
  1518.  
  1519.  
  1520. // <WME Fancy permalink> - http://userscripts.org/users/548866
  1521. function getId(node) {
  1522. return document.getElementById(node);
  1523. }
  1524.  
  1525. function getForumUserIdFromID(wmeUserID)
  1526. {
  1527. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'call getForumUserIdFromID(' + wmeUserID + ')');
  1528. var userName=W.model.users.getObjectById(wmeUserID);
  1529. if(wmer_Debug) console.dir(userName);
  1530. return (getForumUserIdFromName(userName.userName));
  1531. }
  1532.  
  1533. function getForumUserIdFromName(userName)
  1534. {
  1535. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'call getForumUserIdFromName(' + userName + ')');
  1536. var forumID=-1;
  1537. var forumIDs=new Array();
  1538.  
  1539. if (userName.indexOf('/')!=-1)
  1540. {
  1541. var userNames=userName.split('/');
  1542. for (var i=0; i<userNames.length; i++)
  1543. {
  1544. forumID=getForumUserIdFromName(userNames[i]);
  1545. forumIDs[i]=forumID[0];
  1546. }
  1547. return forumIDs;
  1548. }
  1549.  
  1550. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'looking for ' + userName + ' in the forum.');
  1551.  
  1552. var xhr3_object;
  1553.  
  1554. if(window.XMLHttpRequest) // Firefox & Chrome
  1555. xhr3_object = new XMLHttpRequest();
  1556. else if(window.ActiveXObject) // Internet Explorer
  1557. xhr3_object = new ActiveXObject("Microsoft.XMLHTTP");
  1558.  
  1559. xhr3_object.open("GET", "https://www.waze.com/forum/memberlist.php?username=" + userName, false);
  1560.  
  1561. xhr3_object.onreadystatechange = function() {
  1562. if(xhr3_object.readyState == 4)
  1563. {
  1564. var test = xhr3_object.responseText.match(/u=([0-9]+)"/g);
  1565. if (test==null)
  1566. {
  1567. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'Forum return null');
  1568. return(-1); // no match
  1569. }
  1570. if (test.length>1)
  1571. {
  1572. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'Forum return multiple match:');
  1573. if(wmer_Debug) console.dir(test);
  1574. return(-2); // multiple match
  1575. }
  1576. forumID=test[0].substring(2, test[0].length-1);
  1577. }
  1578. };
  1579.  
  1580. if(wmer_Debug) console.dir(xhr3_object);
  1581.  
  1582. try {
  1583. xhr3_object.send(null);
  1584. }
  1585. catch (err) {
  1586. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'XMLHttpRequest error: ' +err.name);
  1587. if(wmer_Debug) console.dir(err);
  1588. return(-3);
  1589. }
  1590. forumIDs[0]=forumID;
  1591. return (forumIDs);
  1592. }
  1593.  
  1594. function click_submitPMForm()
  1595. {
  1596. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'click_submitPMForm() start');
  1597. if (typeof W.selectionManager === "undefined")
  1598. {
  1599. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.selectionManager not found');
  1600. return;
  1601. }
  1602.  
  1603. var wmeSelected=GetWMESelected();
  1604. if (!wmeSelected.length)
  1605. {
  1606. alert(wmer_LanguageRU?'Сначала необходимо выделить сегмент':'Please, select one segment before');
  1607. return false;
  1608. }
  1609.  
  1610. //-------------
  1611. var sccObjs=new Array();
  1612. for (var i=0; i < wmeSelected.length; ++i)
  1613. {
  1614. var sccObj = wmer_getCCSD(wmeSelected[i].model);
  1615. if (sccObj.userID==-1)
  1616. {
  1617. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'PM request - Do not PM Admin!');
  1618. alert("Can't PM admin!");
  1619. return false;
  1620. }
  1621.  
  1622. var j;
  1623. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'sccObj.userID='+sccObj.userID);
  1624. for (j=0; j < wmer_UserCache.length; j+=2)
  1625. {
  1626. if (wmer_UserCache[j] === sccObj.userID)
  1627. {
  1628. sccObj.forumuserID=wmer_UserCache[j+1];
  1629. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'found ['+j+']'+wmer_UserCache[j+1]);
  1630. break;
  1631. }
  1632. }
  1633.  
  1634. if (sccObj.forumuserID == "")
  1635. {
  1636. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'not found '+sccObj.userID);
  1637. sccObj.forumuserID=getForumUserIdFromID(sccObj.userID);
  1638. wmer_UserCache.push(sccObj.userID,sccObj.forumuserID);
  1639. }
  1640.  
  1641. sccObjs.push(sccObj);
  1642. }
  1643.  
  1644. var forumIDs=new Array();
  1645. for (let i=0; i < sccObjs.length; ++i)
  1646. forumIDs[i]=sccObjs[i].forumuserID;
  1647. //-------------
  1648.  
  1649. if (forumIDs.length==1 && forumIDs[0]==-1)
  1650. {
  1651. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'PM request - User never logged to the forum...');
  1652. alert(wmer_LanguageRU?'Автор сегмента не найден на форуме':'Sorry: unable to find the user in the forum');
  1653. return false;
  1654. }
  1655. if (forumIDs.length==1 && forumIDs[0]==-2)
  1656. {
  1657. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'PM request - Several users match name. Should never happen :s');
  1658. alert(wmer_LanguageRU?'Найдено более одного пользователя\nОтправьте сообщение самостоятельно.':'Sorry: more than one user found in the forum.\nYou should look for him/her by yourself.');
  1659. return false;
  1660. }
  1661. if (forumIDs.length==1 && forumIDs[0]==-3)
  1662. {
  1663. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'A network error occurred.');
  1664. alert(wmer_LanguageRU?'Сетевые проблемы\nОтправьте сообщение самостоятельно.':'Sorry: a network error occurred.\nYou should look for him/her by yourself.');
  1665. return false;
  1666. }
  1667.  
  1668. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'PM request - all OK. go to PM!');
  1669.  
  1670. var formID="WMER-PM-FORM";
  1671.  
  1672. var nodePM;
  1673.  
  1674. if (getId("WMER-PM-Send") == null)
  1675. {
  1676. nodePM= document.createElement('div');
  1677. nodePM.id = 'WMER-PM-Send';
  1678. nodePM.style.display='hidden';
  1679. getId(CreateID()).appendChild(nodePM);
  1680. }
  1681. else
  1682. {
  1683. nodePM=getId("WMER-PM-Send");
  1684. }
  1685.  
  1686. var PMForm;
  1687. PMForm='<form id="' + formID + '" target="_blank" method="post" style="display: inline">';
  1688. PMForm+='<input id="' + formID + '-subject" type="hidden" name="subject" value="" />';
  1689. PMForm+='<input type="hidden" name="addbbcode20" value="100" />';
  1690. PMForm+='<input id="' + formID + '-message" type="hidden" name="message" value="" />';
  1691. PMForm+='<input type="hidden" name="preview" value="Preview" />';
  1692. PMForm+='<input type="hidden" name="attach_sig" value="on" />';
  1693. PMForm+='<input id="' + formID + '-ct" type="hidden" name="creation_time" value="0" />';
  1694. PMForm+='<input id="' + formID + '-lc" type="hidden" name="lastclick" value="0" />';
  1695. for (let i=0; i<forumIDs.length; i++)
  1696. {
  1697. PMForm+='<input type="hidden" name="address_list[u]['+forumIDs[i]+']" value="to" />';
  1698. }
  1699. PMForm+='</form>';
  1700. nodePM.innerHTML=PMForm;
  1701.  
  1702. var permalink=wmer_generate_permalink();
  1703. //if(wmer_Debug) console.log(permalink);
  1704. var name_object=""
  1705. let linkParts=permalink.replace(/#/g, "").split('&');
  1706. for (let j=0; j<linkParts.length; j++)
  1707. {
  1708. if (linkParts[j].indexOf("segments=")==0 || linkParts[j].indexOf("venues=")==0 || linkParts[j].indexOf("cameras=")==0 || linkParts[j].indexOf("bigJunctions=")==0)
  1709. {
  1710. name_object=linkParts[j].split('=')[0]
  1711. linkParts.splice (j,1);
  1712. break;
  1713. }
  1714. }
  1715. permalink=linkParts.join('&');
  1716.  
  1717. if(wmer_Debug) console.dir(linkParts);
  1718.  
  1719. var message=wmer_LanguageRU?
  1720. 'Есть вопросы по правкам в [url=' + permalink + ']этой области редактирования[/url]:\n\n':
  1721. 'Some questions about [url=' + permalink + ']this area[/url]:\n\n';
  1722.  
  1723. function NullToEmpty(s)
  1724. {
  1725. return !s?"":s;
  1726. }
  1727. function GetTypeName(s)
  1728. {
  1729. if(wmer_LanguageRU)
  1730. {
  1731. switch(s)
  1732. {
  1733. case "segment": return "сегмент"
  1734. case "venue": return "ПОИ"
  1735. case "node": return "узел"
  1736. case "camera": return "камера"
  1737. case "bigJunction": return "развязка"
  1738. }
  1739. }
  1740. return s
  1741. //'+(wmer_LanguageRU?'Категории':'Categories')+'
  1742. }
  1743.  
  1744. for (let i=0; i < sccObjs.length; ++i)
  1745. {
  1746. var on=sccObjs[i].type === "segment"?(wmer_LanguageRU?'Улица':"Street"):(wmer_LanguageRU?'Название':"Name");
  1747. message += ''
  1748. + (wmer_LanguageRU?'Автор':'Author')+': [b]' + sccObjs[i].username + '[/b]\n'
  1749. + (wmer_LanguageRU?'Тип':'Type')+': [b]' + GetTypeName(sccObjs[i].type) + '[/b]\n'
  1750. + (sccObj.country=='Belarus'?'':(wmer_LanguageRU?'Страна':'Country')+': [b]' + sccObjs[i].country + '[/b]\n')
  1751. + (wmer_LanguageRU?'НП':'City')+': [b]' + NullToEmpty(sccObjs[i].city) + '[/b]\n'
  1752. + (sccObjs[i].poiaddress.length > 0?(wmer_LanguageRU?'Адрес':'Address')+': [b]'+sccObjs[i].poiaddress+'[/b]\n':'')
  1753. + on+ ': [b]' + NullToEmpty(sccObjs[i].street) + '[/b]\n'
  1754. + (wmer_LanguageRU?'Дата':'Date')+': [b]' + timeConverter(sccObjs[i].updatedOn).replace('+',' ') + '[/b]\n'
  1755. + (wmer_LanguageRU?'Ссылка':'Permalink')+': [url]' + permalink + '&' + name_object + '=' + sccObjs[i].objid + '[/url]\n'
  1756. + (wmer_LanguageRU?'Дополнительно':'Description')+': {' + NullToEmpty(sccObjs[i].description) + '\n}\n'
  1757. + '\n';
  1758. }
  1759. //if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + message);
  1760.  
  1761. getId(formID + '-message').value=message;
  1762. var now=new Date().getTime();
  1763. now /= 1000;
  1764. now = Math.floor(now);
  1765. getId(formID + '-ct').value=now;
  1766. getId(formID + '-lc').value=now;
  1767.  
  1768. getId(formID).action="https://www.waze.com/forum/ucp.php?i=pm&mode=compose&action=post";
  1769. getId(formID + '-subject').value=
  1770. wmer_LanguageRU?
  1771. '[WME Request] Уточнение по правкам':
  1772. '[WME Request] Question about map edits';
  1773.  
  1774. if(wmer_Debug) console.dir(getId(formID));
  1775.  
  1776. getId(formID).submit();
  1777. return true; // this forces to open in new tab!
  1778. }
  1779. // </WME Fancy permalink>
  1780.  
  1781.  
  1782. function wmer_HandCreateRequest()
  1783. {
  1784. if ((typeof arguments[0]) === "object")
  1785. {
  1786. switch(arguments[0].type)
  1787. {
  1788. case 'click': // click button
  1789. {
  1790. var e=document.getElementById(arguments[0].id);
  1791. if(e)
  1792. e.click();
  1793.  
  1794. break;
  1795. }
  1796. }
  1797. }
  1798. }
  1799.  
  1800. function wmer_initBindKey() {
  1801. var Config =[
  1802. {handler: 'WMERequest_Lock', title: "Запрос на изменение уровня блокировки объекта", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_lock'}},
  1803. {handler: 'WMERequest_Join', title: "Запрос на присоединение сегментов", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_join'}},
  1804. {handler: 'WMERequest_Dir', title: "Запрос на изменение направления сегментов", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_dir'}},
  1805. {handler: 'WMERequest_Turn', title: "Запрос на изменение разрешения поворотов", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_turn'}},
  1806. {handler: 'WMERequest_Closures', title: "Запрос на перекрытие сегментов", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_closures'}},
  1807. {handler: 'WMERequest_City', title: "Запрос на создание/изменение НП", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerBtn_cl'}},
  1808. ];
  1809. /*
  1810. W.loginManager.user.editableCountryIDs
  1811. 186 - Russia
  1812. 180 - Poland
  1813. 123 - Latvia
  1814. 37 - Belarus
  1815. 129 - Lithuania
  1816. 232 - Ukraine
  1817. */
  1818. if(W.loginManager.user.rank >= 4 || (W.loginManager.user.editableCountryIDs.indexOf(37) >= 0 && W.loginManager.user.rank >= 3)) // ??? Uzbekistan ???
  1819. {
  1820. Config.push({handler: 'WMERequest_CitySave', title: "Сохранить название НП", func:wmer_HandCreateRequest , key:-1, arg:{type:'click',id:'wmerA_cl'}});
  1821. }
  1822.  
  1823. for(var i=0; i < Config.length; ++i)
  1824. {
  1825. WMEKSRegisterKeyboardShortcut('WME-Requests', 'WME-Requests', Config[i].handler, Config[i].title, Config[i].func, Config[i].key, Config[i].arg);
  1826. }
  1827.  
  1828. WMEKSLoadKeyboardShortcuts('WME-Requests');
  1829.  
  1830. window.addEventListener("beforeunload", function() {
  1831. WMEKSSaveKeyboardShortcuts('WME-Requests');
  1832. }, false);
  1833.  
  1834. }
  1835.  
  1836. function wmer_FakeLoad()
  1837. {
  1838. if (typeof W === "undefined")
  1839. {
  1840. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'Waze not found, retrying in 500ms...');
  1841. setTimeout(wmer_FakeLoad,500);
  1842. return;
  1843. }
  1844. if (typeof W.selectionManager === "undefined")
  1845. {
  1846. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.selectionManager not found, retrying in 500ms...');
  1847. setTimeout(wmer_FakeLoad,500);
  1848. return;
  1849. }
  1850. if (typeof W.model === "undefined")
  1851. {
  1852. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.model not found, retrying in 500ms...');
  1853. setTimeout(wmer_FakeLoad,500);
  1854. return;
  1855. }
  1856. if (typeof W.loginManager === "undefined")
  1857. {
  1858. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.loginManager not found, retrying in 500ms...');
  1859. setTimeout(wmer_FakeLoad,500);
  1860. return;
  1861. }
  1862. if (typeof W.loginManager.user === "undefined")
  1863. {
  1864. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'W.loginManager.user not found, retrying in 500ms...');
  1865. setTimeout(wmer_FakeLoad,500);
  1866. return;
  1867. }
  1868.  
  1869. try {
  1870. W.selectionManager.events.register("selectionchanged", null, wmer_insertButton);
  1871. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'added event handler for selectionchanged');
  1872. }
  1873. catch (err) {
  1874. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'added event handler error: ' +err.name);
  1875. }
  1876. setTimeout(wmer_initBindKey, 500);
  1877. }
  1878.  
  1879.  
  1880. function wmer_Init() {
  1881. if(wmer_Debug) console.log('WME Requests v.' + wmer_Version + ': ' + 'init');
  1882. setTimeout(wmer_FakeLoad, 500);
  1883. }
  1884.  
  1885.  
  1886. function wmer_bootstrap()
  1887. {
  1888. wmer_LanguageRU=I18n.locale === "ru"?true:false;
  1889.  
  1890. wmer_Debug = __GetLocalStorageItem("wmer_Debug",'bool',false);
  1891. //WMELanguageRU = __GetLocalStorageItem("WMELanguageRU",'bool',false);
  1892. wmer_MapCenter = __GetLocalStorageItem("WMERequestMapCenter",'bool',false);
  1893. wmer_AddCounty = true;//__GetLocalStorageItem("WMERequestAddCounty",'bool',false);
  1894. WMERequestEmail = __GetLocalStorageItem("WMERequestEmail",'string','');
  1895. WMERequestCountry= __GetLocalStorageItem("WMERequestCountry",'int',0);
  1896. wmer_SendDiscord = __GetLocalStorageItem("wmer_SendDiscord",'bool',false);
  1897.  
  1898. wmer_Init();
  1899. }
  1900.  
  1901. wmer_bootstrap();
  1902.  
  1903.  
  1904. function __GetLocalStorageItem(Name,Type,Def,Arr)
  1905. {
  1906. //if (wme2GIS_debug) console.log("__GetLocalStorageItem(): Name="+Name+",Type="+Type+",Def="+Def+",Arr="+Arr);
  1907. var tmp0=localStorage.getItem(Name);
  1908. if (tmp0)
  1909. {
  1910. switch(Type)
  1911. {
  1912. case 'string':
  1913. break;
  1914. case 'bool':
  1915. tmp0=(tmp0 === "true" || tmp0 === "1")?true:false;
  1916. break;
  1917. case 'int':
  1918. tmp0=(!isNaN(parseInt(tmp0)))?parseInt(tmp0):0;
  1919. break;
  1920. case 'arr':
  1921. if (tmp0.length > 0)
  1922. if(!Arr[tmp0])
  1923. tmp0=Def;
  1924. break;
  1925. }
  1926. }
  1927. else
  1928. tmp0=Def;
  1929. return tmp0;
  1930. }
  1931.  
  1932.  
  1933.  
  1934. // from: https://greasyfork.org/ru/scripts/16071-wme-keyboard-shortcuts (modify)
  1935. /*
  1936. when adding shortcuts each shortcut will need a uniuque name
  1937. the command to add links is WMERegisterKeyboardShortcut(ScriptName, ShortcutsHeader, NewShortcut, ShortcutDescription, FunctionToCall, ShortcutKeysObj) {
  1938. ScriptName: This is the name of your script used to track all of your shortcuts on load and save.
  1939. ScriptName: replace 'WMEAwesome' with your scripts name such as 'SomeOtherScript'
  1940. ShortcutsHeader: this is the header that will show up in the keyboard editor
  1941. NewShortcut: This is the name of the shortcut and needs to be uniuque from all of the other shortcuts, from other scripts, and WME
  1942. ShortcutDescription: This wil show up as the text next to your shortcut
  1943. FunctionToCall: this is the name of your function that will be called when the keyboard shortcut is presses
  1944. ShortcutKeysObj: the is the object representing the keys watched set this to '-1' to let the users specify their own shortcuts.
  1945. ShortcutKeysObj: The alt, shift, and ctrl keys are A=alt, S=shift, C=ctrl. for short cut to use "alt shift ctrl and l" the object would be 'ASC+l'
  1946. */
  1947. function WMEKSRegisterKeyboardShortcut(a,b,c,d,e,f,g){try{I18n.translations[I18n.locale].keyboard_shortcuts.groups[a].members.length}catch(c){W.accelerators.Groups[a]=[],W.accelerators.Groups[a].members=[],I18n.translations[I18n.locale].keyboard_shortcuts.groups[a]=[],I18n.translations[I18n.locale].keyboard_shortcuts.groups[a].description=b,I18n.translations[I18n.locale].keyboard_shortcuts.groups[a].members=[]}if(e&&"function"==typeof e){I18n.translations[I18n.locale].keyboard_shortcuts.groups[a].members[c]=d,W.accelerators.addAction(c,{group:a});var i="-1",j={};j[i]=c,W.accelerators._registerShortcuts(j),null!==f&&(j={},j[f]=c,W.accelerators._registerShortcuts(j)),W.accelerators.events.register(c,null,function(){e(g)})}else alert("The function "+e+" has not been declared")}function WMEKSLoadKeyboardShortcuts(a){if(console.log("WMEKSLoadKeyboardShortcuts("+a+")"),localStorage[a+"KBS"])for(var b=JSON.parse(localStorage[a+"KBS"]),c=0;c<b.length;c++)try{W.accelerators._registerShortcuts(b[c])}catch(a){console.log(a)}}function WMEKSSaveKeyboardShortcuts(a){console.log("WMEKSSaveKeyboardShortcuts("+a+")");var b=[];for(var c in W.accelerators.Actions){var d="";if(W.accelerators.Actions[c].group==a){W.accelerators.Actions[c].shortcut?(W.accelerators.Actions[c].shortcut.altKey===!0&&(d+="A"),W.accelerators.Actions[c].shortcut.shiftKey===!0&&(d+="S"),W.accelerators.Actions[c].shortcut.ctrlKey===!0&&(d+="C"),""!==d&&(d+="+"),W.accelerators.Actions[c].shortcut.keyCode&&(d+=W.accelerators.Actions[c].shortcut.keyCode)):d="-1";var e={};e[d]=W.accelerators.Actions[c].id,b[b.length]=e}}localStorage[a+"KBS"]=JSON.stringify(b)}
  1948. /* ********************************************************** */
  1949.  
  1950. // from https://github.com/lgarron/clipboard.js/blob/master/clipboard.min.js
  1951. // АХТУНГ!!! если вызов в $.ajax, то ставим параметр "async: false,"
  1952. (function(f,c){"undefined"!==typeof module?module.exports=c():"function"===typeof define&&"object"===typeof define.amd?define(c):this[f]=c()})("clipboard",function(){if(!document.addEventListener)return null;var f={};f.copy=function(){function c(){d=!1;b=null;e&&window.getSelection().removeAllRanges();e=!1}var d=!1,b=null,e=!1;document.addEventListener("copy",function(c){if(d){for(var e in b)c.clipboardData.setData(e,b[e]);c.preventDefault()}});return function(g){return new Promise(function(k,f){d=!0;b="string"===typeof g?{"text/plain":g}:g instanceof Node?{"text/html":(new XMLSerializer).serializeToString(g)}:g;try{var n=document.getSelection();if(!document.queryCommandEnabled("copy")&&n.isCollapsed){var l=document.createRange();l.selectNodeContents(document.body);n.addRange(l);e=!0}if(document.execCommand("copy"))c(),k();else throw Error("Unable to copy. Perhaps it's not available in your browser?");}catch(p){c(),f(p)}})}}();f.paste=function(){var c=!1,d,b;document.addEventListener("paste",function(e){if(c){c=!1;e.preventDefault();var g=d;d=null;g(e.clipboardData.getData(b))}});return function(e){return new Promise(function(g,f){c=!0;d=g;b=e||"text/plain";try{document.execCommand("paste")||(c=!1,f(Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")))}catch(m){c=!1,f(Error(m))}})}}();"undefined"===typeof ClipboardEvent&&"undefined"!==typeof window.clipboardData&&"undefined"!==typeof window.clipboardData.setData&&(function(c){function d(a,b){return function(){a.apply(b,arguments)}}function b(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._value=this._state=null;this._deferreds=[];l(a,d(f,this),d(k,this))}function e(a){var b=this;return null===this._state?void this._deferreds.push(a):void p(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var h;try{h=c(b._value)}catch(d){return void a.reject(d)}a.resolve(h)})}function f(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var b=a.then;if("function"==typeof b)return void l(d(b,a),d(f,this),d(k,this))}this._state=!0;this._value=a;m.call(this)}catch(c){k.call(this,c)}}function k(a){this._state=!1;this._value=a;m.call(this)}function m(){for(var a=0,b=this._deferreds.length;b>a;a++)e.call(this,this._deferreds[a]);this._deferreds=null}function n(a,b,c,h){this.onFulfilled="function"==typeof a?a:null;this.onRejected="function"==typeof b?b:null;this.resolve=c;this.reject=h}function l(a,b,c){var h=!1;try{a(function(a){h||(h=!0,b(a))},function(a){h||(h=!0,c(a))})}catch(d){h||(h=!0,c(d))}}var p=b.immediateFn||"function"==typeof setImmediate&&setImmediate||function(a){setTimeout(a,1)},q=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};b.prototype["catch"]=function(a){return this.then(null,a)};b.prototype.then=function(a,c){var d=this;return new b(function(b,f){e.call(d,new n(a,c,b,f))})};b.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&q(arguments[0])?arguments[0]:arguments);return new b(function(b,c){function d(e,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var k=g.then;if("function"==typeof k)return void k.call(g,function(a){d(e,a)},c)}a[e]=g;0===--f&&b(a)}catch(l){c(l)}}if(0===a.length)return b([]);for(var f=a.length,e=0;e<a.length;e++)d(e,a[e])})};b.resolve=function(a){return a&&"object"==typeof a&&a.constructor===b?a:new b(function(b){b(a)})};b.reject=function(a){return new b(function(b,c){c(a)})};b.race=function(a){return new b(function(b,c){for(var d=0,e=a.length;e>d;d++)a[d].then(b,c)})};"undefined"!=typeof module&&module.exports?module.exports=b:c.Promise||(c.Promise=b)}(this),f.copy=function(c){return new Promise(function(d,b){if("string"!==typeof c&&!("text/plain"in c))throw Error("You must provide a text/plain type.");window.clipboardData.setData("Text","string"===typeof c?c:c["text/plain"])?d():b(Error("Copying was rejected."))})},f.paste=function(){return new Promise(function(c,d){var b=window.clipboardData.getData("Text");b?c(b):d(Error("Pasting was rejected."))})});return f});
  1953. /* ********************************************************** */