MediaLab Love Chapter 2

Assistance of MediaLab Love about Javascript test and more...

Google Maps検索ボックスに緯度経度を挿入する(改訂版)


以前作ったものを少し改定しました。
bookmarklet:

javascript:(function(){if(document.domain.match(/(maps|www)\.google\.co(m|\.jp)/)){var%20o=document.getElementById('l_near');var%20p=document.getElementById('d_d');var%20q=document.getElementById('d_daddr');var%20input=function(){var%20loc=document.getElementById('link').href;if(loc.match(/[\?&]ll=([\d\.\-]+,[\d\.\-]+)/)){this.value=loc.match(/[\?&]ll=([\d\.\-]+,[\d\.\-]+)/)[1];}else%20if(loc.match(/[\?&]near=(.*?)[&$]/)){this.value=decodeURI(loc.match(/[\?&]near=(.*?)[&$]/)[1]);}else%20if(loc.match(/[\?&]q=(.*?)[&$]/)){this.value=decodeURI(loc.match(/[\?&]q=(.*?)[&$]/)[1]);}};o.addEventListener('dblclick',input,false);p.addEventListener('dblclick',input,false);q.addEventListener('dblclick',input,false);}})();

greasemonkeyスクリプト
http://userscripts.org/scripts/source/11284.user.js
機能は変わっていません。対象となるウェブサイトを増やしただけです。

// ==UserScript==
// @name          insert location info into Google Maps search box
// @namespace     http://d.hatena.ne.jp/Koumei_S/
// @description	  inserts lat/long info into Google Maps by double-clicking at search box.
// @include       http://maps.google.co.jp/*
// @include       http://maps.google.com/*
// @include       http://www.google.co.jp/maps*
// @include       http://www.google.com/maps*
// @version       1.2
// ==/UserScript==

(function(){
	var o=document.getElementById('l_near');
	var p=document.getElementById('d_d');
	var q=document.getElementById('d_daddr');
	var input=function(){
		var loc=document.getElementById('link').href;
		if(loc.match(/[\?&]ll=([\d\.\-]+,[\d\.\-]+)/)){
			this.value=loc.match(/[\?&]ll=([\d\.\-]+,[\d\.\-]+)/)[1];
		}
		else if(loc.match(/[\?&]near=(.*?)[&$]/)){
			this.value=decodeURI(loc.match(/[\?&]near=(.*?)[&$]/)[1]);
		}
		else if(loc.match(/[\?&]q=(.*?)[&$]/)){
			this.value=decodeURI(loc.match(/[\?&]q=(.*?)[&$]/)[1]);
		}
	};
	o.addEventListener('dblclick',input,false);
	p.addEventListener('dblclick',input,false);
	q.addEventListener('dblclick',input,false);
})();