OndeTemBanrisul

Mostra em um mapa no site do Banrisul onde ficam as agencias bancarias

  1. // ==UserScript==
  2. // @name OndeTemBanrisul
  3. // @namespace http://stackoverflow.com/users/982924/rasg
  4. // @author RASG
  5. // @description Mostra em um mapa no site do Banrisul onde ficam as agencias bancarias
  6. // @require http://code.jquery.com/jquery.min.js
  7. // @require https://maps.google.com/maps/api/js?sensor=false&region=BR&callback=initialize
  8. // @require https://greasyfork.org/scripts/2199-waitforkeyelements/code/waitForKeyElements.js?version=5802
  9. // @include http*://*banrisul.com.br/bob/link/bobw00hn_onde_tem_banrisul.aspx?secao_id=111*
  10. // @version 2012.11.13
  11. // ==/UserScript==
  12.  
  13. /*
  14. ----------------------------------------------------------------------------
  15. METODO DE CARREGAMENTO DO JQUERY (metodo_JQ):
  16. 1 = usar o @require do greasemonkey
  17. 2 = carregar o script de jquery.com e inserir na pagina
  18. Tente usar primeiro o metodo padrao (1) que e mais rapido
  19. Caso o script nao funcione, altere para (2)
  20. Se ainda assim nao funcionar, informe na pagina do script em userscripts.org
  21. ----------------------------------------------------------------------------
  22. */
  23.  
  24. if (window.$ == undefined) { metodo_JQ(1) }
  25. else { $ = window.$ }
  26.  
  27. var ArrCoord = [];
  28. var ArrAdrress = [];
  29.  
  30. $(window).load(function(){
  31.  
  32. var DIVmapa = document.createElement('div');
  33. DIVmapa.id = 'DIVmapa';
  34. DIVmapa.style.border = '2px coral solid';
  35. DIVmapa.style.cursor = 'pointer';
  36. DIVmapa.style.display = '';
  37. DIVmapa.style.height = '80%';
  38. DIVmapa.style.margin = '1';
  39. DIVmapa.style.overflow = 'hidden';
  40. DIVmapa.style.position = 'fixed';
  41. DIVmapa.style.padding = '1';
  42. DIVmapa.style.right = '1%';
  43. DIVmapa.style.top = '1%';
  44. DIVmapa.style.width = '35%';
  45. DIVmapa.style.zIndex = '998';
  46.  
  47. var DIVinterna = document.createElement('div');
  48. DIVinterna.id = 'DIVinterna';
  49. DIVinterna.style.height = '100%';
  50. DIVinterna.style.width = '100%';
  51. DIVinterna.style.zIndex = '999';
  52.  
  53. var DIVendereco = document.createElement('div');
  54. DIVendereco.id = 'DIVendereco';
  55. DIVendereco.style.border = '1px pink solid';
  56. DIVendereco.style.zIndex = '997';
  57.  
  58. $(DIVmapa).append(DIVendereco)
  59. $(DIVmapa).append(DIVinterna)
  60. $(DIVmapa).appendTo('body')
  61.  
  62. $('#ctl00_ctl00_ExtraConteudo03_ExtraConteudo03_listaAg tr[class!=linhaHeader]').each(function(index) {
  63. var ag = $.trim( $(this).children().filter('.colunaNome.itemEsquerda').text() );
  64. var cod = $.trim( $(this).children().filter('.colunaCodInternet.item.posicao').text() );
  65. var cidade = ' ' + $.trim( $('#ctl00_ctl00_Conteudo_MainContent_lblCidadeSelecionada').text() );
  66. var rua = $(this).children().filter('.colunaEndereco.item').text().replace(/(.*?\d*[^\D])/gi, '$1');
  67. var endereco = $.trim( rua.replace(/\s{2,}/g, ' ') ) + cidade;
  68. var fone = $.trim( $(this).children().filter('.colunaFone.item').text() );
  69.  
  70. ArrAdrress.push(endereco)
  71. //console.log('adicionado ao ArrAdrress : ' + endereco)
  72. })
  73. metodo_Gmaps(2);
  74.  
  75. });
  76.  
  77. initialize = setTimeout(function () {
  78.  
  79. google = unsafeWindow.google;
  80. directionsService = new google.maps.DirectionsService();
  81. directionsDisplay = new google.maps.DirectionsRenderer();
  82. geocoder = new google.maps.Geocoder();
  83.  
  84. var DetectedPosition = function(position) {
  85. var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
  86. addMarker(userLatLng, 'Detected location')
  87. }
  88.  
  89. var PortoAlegre = new google.maps.LatLng(-30.034176,-51.229212);
  90. var myOptions = {
  91. zoom: 12,
  92. mapTypeId: google.maps.MapTypeId.ROADMAP,
  93. center: PortoAlegre
  94. }
  95. map = new google.maps.Map(document.getElementById("DIVinterna"), myOptions);
  96. navigator.geolocation.getCurrentPosition(DetectedPosition);
  97.  
  98. for (var i = 0; i < ArrAdrress.length; i++) {
  99. window.setTimeout( trap(geocodificar, [i, ArrAdrress, ArrCoord]), [i]*1000 )
  100. }
  101. /*
  102. for (i = 0; i < ArrCoord.length; i++) {
  103. var LatiLongi = new google.maps.LatLng(ArrCoord[i][1], ArrCoord[i][2])
  104. var PlaceName = ArrCoord[i][0]
  105. addMarker(LatiLongi, PlaceName)
  106. }
  107. */
  108. for (var x = 0; x < ArrCoord.length; x++) {
  109. console.log( 'ArrCoord : ' + ArrCoord[x] )
  110. }
  111.  
  112. }, 1000);
  113.  
  114. function geocodificar(i, ArrAdrress, ArrCoord) {
  115. geocoder.geocode({ 'address': ArrAdrress[i]}, function (results, status) {
  116. if (status == google.maps.GeocoderStatus.OK) {
  117. addMarker(results[0].geometry.location, 'ponto '+[i])
  118. ArrCoord.push(results[0].geometry.location)
  119. }
  120. else {
  121. console.log("ERRO no Geocode : " + status);
  122. }
  123. })
  124. //console.log( 'address no geocoder : ' + ArrAdrress[i] )
  125. }
  126.  
  127. trap = function (fn, args) {
  128. return function() {
  129. return fn.apply(this, args);
  130. };
  131. };
  132.  
  133. function addMarker(coord, plcname) {
  134. var marker = new google.maps.Marker({
  135. draggable: false,
  136. map: map,
  137. position: coord,
  138. title: plcname
  139. });
  140. var infowindow = new google.maps.InfoWindow({
  141. content: '<div class="infodiv">'+plcname+'</div>'
  142. });
  143. google.maps.event.addListener(marker, 'click', function() {
  144. //infowindow.setContent(ArrCoord[i][0]);
  145. infowindow.open(map, marker);
  146. });
  147. }
  148.  
  149. function metodo_JQ(metodo){
  150. JQ = "http://code.jquery.com/jquery.js";
  151. JQmin = "http://code.jquery.com/jquery.min.js";
  152.  
  153. if (metodo == 2) {
  154. var script = document.createElement('script');
  155. script.src = JQmin;
  156. var head = document.getElementsByTagName("head")[0];
  157. (head || document.body).appendChild(script);
  158. };
  159. };
  160.  
  161. function metodo_Gmaps(metodo){
  162. API_js_callback = "https://maps.google.com.br/maps/api/js?sensor=false&region=BR&callback=initialize";
  163.  
  164. if (metodo == 2) {
  165. var script = document.createElement('script');
  166. script.src = API_js_callback;
  167. var head = document.getElementsByTagName("head")[0];
  168. (head || document.body).appendChild(script);
  169. };
  170. };