OSM Directions

Replaces the links to GoogleDirections to OpenStreetMap directions

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

Advertisement:

// ==UserScript==
// @name         OSM Directions
// @namespace    http://technetium.be
// @version      1.6
// @description  Replaces the links to GoogleDirections to OpenStreetMap directions
// @author       Toni Cornelissen ([email protected])
// @include      *
// ==/UserScript==

(function() {
    'use strict';

    function main() {
        console.log("OSM Directions");
        window.addEventListener('click', function(e) {
            let target = e.target;
            while (('A' !== target.tagName) && target.parentElement) {
                target = target.parentElement;
            }
            if ('A' != target.tagName) {
            	return;
            }
            let orig = '';
            let dest = '';
			let query = '';
            if (target.href.startsWith('https://maps.google.com/maps?f=d')) {
                orig = target.href.replace(/.*saddr=/, '').replace(/%20.*/, '');
                dest = target.href.replace(/.*daddr=/, '').replace(/%20.*/, '');
            } else if (target.href.startsWith('https://www.google.com/maps/dir/?api=1')) {
                dest = target.href.replace(/.*destination=/, '').replace(/&.*/, '');
            } else if (target.href.startsWith('https://www.google.com/maps?q=')) {
				query = target.href.replace(/.*\?q=/, '');
				console.log('QUERY: ',	query);
            } 
            if (dest) {
                e.preventDefault();
                location.href = 'https://www.openstreetmap.org/directions?route='+orig+'%3B'+dest;
            }
			if (query) {
                e.preventDefault();
                location.href = 'https://www.openstreetmap.org?query='+query;
			}
        });
    }
    main();
})();