OSM Directions

Replaces the links to GoogleDirections to OpenStreetMap directions

  1. // ==UserScript==
  2. // @name OSM Directions
  3. // @namespace http://technetium.be
  4. // @version 1.4
  5. // @description Replaces the links to GoogleDirections to OpenStreetMap directions
  6. // @author Toni Cornelissen (github@technetium.be)
  7. // @match *://*.geocaching.com/geocache/*
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. function main() {
  14. window.addEventListener('click', function(e) {
  15. if ('A' != e.target.tagName) { return; }
  16. if (e.target.href.startsWith('https://maps.google.com/maps?f=d')) {
  17. e.preventDefault();
  18. const orig = e.target.href.replace(/.*saddr=/, '').replace(/%20.*/, '');
  19. const dest = e.target.href.replace(/.*daddr=/, '').replace(/%20.*/, '');
  20. location.href = 'https://www.openstreetmap.org/directions?route='+orig+'%3B'+dest;
  21. }
  22. });
  23. }
  24. main();
  25. })();