// LocaPoint linkify // Author: Nao Ueda // Locazing Inc. http://www.locapoint.com // Version: 1.0 - 16Apr2006 - Initial Release // License: GNU GPL v2 or later // // // This Code bollows, copyes, and imitates from following User scripts. I really thank these authors. // UPS Tracking Linkify (http://plutor.org/files/upslinkify.user.js) by Logan Ingalls, // VoIP Dial Linkify (http://www.muehlen.com/projects/voip/voip_dial.user.js) by Ralf Muehlen, // and mostly // Postcode linkify (http://www.qwghlm.co.uk/projects/postcodelinkify.user.js) by Chris Applegate. // // Usage: // Search for a location information ponited by LocaPoint(TM), // Turn into hyperlink to the relevant location on Google Maps, // and Add a Title with Latitude/Longitude information // // // ==UserScript== // @name LocaPoint Linkify // @namespace http://www.locapoint.com/ // @description Hyperlinkifies any LocaPoint into into a link to the Google Map for that location // @include * // ==/UserScript== (function () { // URL of the map lookup mapURL = "http://maps.google.com/?q="; // Locapoint Pattern:"AA0.AA0.AA0.AA0" const lpRegex = /([A-Z]{2}\d\.){3}[A-Z]{2}\d/g; //tags we will scan looking for un-hyperlinked urls var allowedParents = [ "abbr", "acronym", "address", "applet", "b", "bdo", "big", "blockquote", "body", "caption", "center", "cite", "code", "dd", "del", "div", "dfn", "dt", "em", "fieldset", "font", "form", "h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "ins", "kdb", "li", "object", "pre", "p", "q", "samp", "small", "span", "strike", "s", "strong", "sub", "sup", "td", "th", "tt", "u", "var"]; // Xpath statement var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ")]"; // Pick out all text nodes in page that have an allowed parent var candidates = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); // For each candidate... for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) { // See if it contains our regexp, if it does... if (lpRegex.test(cand.nodeValue)) { // Create a new initially blank node to put in text's place var span = document.createElement("span"); var source = cand.nodeValue; cand.parentNode.replaceChild(span, cand); // Go through each instance lpRegex.lastIndex = 0; for (var match = null, lastLastIndex = 0; (match = lpRegex.exec(source)); ) { // Convert LocaPoint into Latitude and Longitude var location = Locapoint2LatLon(match[0]); // Then create a hyperlink var a = document.createElement("a"); a.setAttribute("href", mapURL + location.latitude + "," + location.longitude); a.setAttribute("title", "lat,lon= " + location.latitude + "," + location.longitude); // Set linktext to be LocaPoint a.appendChild(document.createTextNode(match[0])); // Add text between end of previous instance and start of this one span.appendChild(document.createTextNode(source.substring(lastLastIndex, match.index))); // Add the hyperlink in span.appendChild(a); // Remember the end index of this instance lastLastIndex = lpRegex.lastIndex; } // Add the rest of the text in span.appendChild(document.createTextNode(source.substring(lastLastIndex))); span.normalize(); // All done! } } function Locapoint2LatLon(locapoint){ var location = new Object(); location.latitude =( ((locapoint.charCodeAt(0)-65)*1757600 +(locapoint.charCodeAt(1)-65)*67600 +(locapoint.charCodeAt(2)-48)*6760 +(locapoint.charCodeAt(8)-65)*260 +(locapoint.charCodeAt(9)-65)*10 +(locapoint.charCodeAt(10)-48)) *180/45697600-90).toFixed(6); location.longitude = ( ((locapoint.charCodeAt(4)-65)*1757600 +(locapoint.charCodeAt(5)-65)*67600 +(locapoint.charCodeAt(6)-48)*6760 +(locapoint.charCodeAt(12)-65)*260 +(locapoint.charCodeAt(13)-65)*10 +(locapoint.charCodeAt(14)-48) ) *360/45697600-180).toFixed(6); return(location); } })();