WMEExtResources

Links for opening external resources at the WME location

当前为 2017-08-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WMEExtResources
  3. // @namespace https://greasyfork.org/users/30701-justins83-waze
  4. // @version 0.3.01
  5. // @description Links for opening external resources at the WME location
  6. // @author JustinS83
  7. // @include https://www.waze.com/editor*
  8. // @include https://www.waze.com/*/editor*
  9. // @include https://beta.waze.com*
  10. // @exclude https://www.waze.com/user/editor*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function init(){
  18. var $section = $("<div>", {style:"padding:8px 16px"});
  19. $section.html([
  20. '<span id="GMaps">',
  21. '<img src="http://i.imgur.com/whsQQFE.png" alt="Google Maps" width="18" height="18" id="GMapsImg" title="Open in Google Maps" style="cursor:pointer; float: left; display:inline-block; margin: 2px 5px 0 3px;">',
  22. '</span>'
  23. ].join(' '));
  24.  
  25. $('.WazeControlPermalink').append($section.html());
  26.  
  27. $('#GMapsImg').click(function(){
  28. let projI = new OpenLayers.Projection("EPSG:900913");
  29. let projE = new OpenLayers.Projection("EPSG:4326");
  30. let center_lonlat = (new OpenLayers.LonLat(Waze.map.center.lon, Waze.map.center.lat)).transform(projI,projE);
  31. let lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
  32. let lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
  33. let lang = I18n.currentLocale().replace("en-US", "en");
  34.  
  35. window.open('https://www.google.com/maps/@' + lat + ',' + lon + ',' + ( W.map.zoom + 12) + 'z' + (lang != "" ? "?hl=" + lang : ""), 'Google Maps');
  36.  
  37. });
  38.  
  39. var $sectionMapillary = $("<div>", {style:"padding:8px 16px"});
  40. $sectionMapillary.html([
  41. '<span id="Mapillary">',
  42. '<img src="https://i.imgur.com/vG2qieS.png" alt="Mapillary" width="18" height="18" id="MapillaryImg" title="Open in Mapillary" style="cursor:pointer; float: left; display:inline-block; margin: 2px 5px 0 3px;">',
  43. '</span>'
  44. ].join(' '));
  45.  
  46. $('.WazeControlPermalink').append($sectionMapillary.html());
  47.  
  48. $('#MapillaryImg').click(function(){
  49. var projI=new OpenLayers.Projection("EPSG:900913");
  50. var projE=new OpenLayers.Projection("EPSG:4326");
  51. var center_lonlat = (new OpenLayers.LonLat(Waze.map.center.lon, Waze.map.center.lat)).transform(projI,projE);
  52. var lat = Math.round(center_lonlat.lat * 1000000) / 1000000;
  53. var lon = Math.round(center_lonlat.lon * 1000000) / 1000000;
  54.  
  55. window.open('https://www.mapillary.com/app/?lat=' + lat + '&lng=' + lon + '&z=' +( W.map.zoom + 11), 'Mapillary');
  56. });
  57.  
  58. }
  59.  
  60. function bootstrap(tries) {
  61. tries = tries || 1;
  62.  
  63. if (window.W &&
  64. window.W.map &&
  65. window.W.model &&
  66. $) {
  67. init();
  68. } else if (tries < 1000) {
  69. setTimeout(function () {bootstrap(tries++);}, 200);
  70. }
  71. }
  72.  
  73. bootstrap();
  74. })();