Sorry, there are no scripts tagged mozillazineforums;global

Direct "Link to this page" in Google Maps

By Ilya Dogolazky Last update Jan 28, 2008 — Installed 84 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
// This JavaScript file is automatically generated by js-tool.
// Do NOT read it! Do NOT edit it! Edit the source code instead.


// Direct "Link to this page" in Google Maps 0.0.3 (alpha) 2008-01-28
// ------------------------------------------
// Copyright (c) 2008 Ilya Dogolazky
// Released under the GPL license, see http://www.gnu.org/copyleft/gpl.html for details
// ------------------------------------------
// ==UserScript==
// @name           Direct "Link to this page" in Google Maps
// @namespace      http://www.math.uni-bonn.de/people/ilyad/gm/direct-link
// @description    You can still open "Paste link in email / embed map in website" dialog by clicking on the chain symbol on the link's left side
// @include        http://maps.google.tld/*
// ==/UserScript==

// File Xpath.js
Xpath.list = function(xpath, root, order)
{
  if(!root)
    root = window.document ;
  var result = [] ;
  var snapshot = document.evaluate(xpath, root, null, (order ? XPathResult.ORDERED_NODE_SNAPSHOT_TYPE : XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE), null) ;
  for(var i=0; i<snapshot.snapshotLength; ++i)
    result.push(snapshot.snapshotItem(i)) ;
  return result ;
}

Xpath.node = function(xpath, root)
{
  return Xpath.list(xpath, root, false)[0] ;
}

Xpath.aNode = function (hash, root)
{
  var list = Xpath.aList(hash, root) ;
  if(list.length==0)
    return null ;
  if(list.length>1)
    GM_log("Multiply nodes found in Xpath.aNode("+hash+")") ;
  return list[0] ;
}

Xpath.aList = function(list, root, order)
{
  var xpath = Xpath.aXpath(list) ;
  return Xpath.list(xpath, root, order) ;
}

Xpath.aXpath = function (list)
{
  var s = [] ;
  while(list.length>0)
  {
    var key = list.shift() ;
    var value = list.shift() ;
    var at = "@" + key ;
    s.push((value==null || value=="*") ? at : at+"='" + value + "'") ;
  }
  return "descendant::*["+s.join(" and ")+"]" ;
}

function Xpath()
{}

// End of file Xpath.js

Main() ;

function Main()
{
  if(window.parent!=window)
    return ;
  var link = document.getElementById("link") ;
  if(!link)
    return ;
  Main.directlink = new DirectLink_v3(link) ;
}

function DirectLink_v3(a)
{
  this.a = a ;
  this.span = Xpath.node(".//span", this.a) ;
  this.span.addEventListener("click", this, false) ;
}

DirectLink_v3.prototype.handleEvent = function(event)
{
  if(event.type == "click" && event.target==this.span)
  {
    event.stopPropagation() ;
  }
}

function DirectLink_v2(a)
{
  this.a = a ;
  var span_txt = Xpath.node(".//span/text()", this.a) ;
  var t = span_txt.nodeValue ;
  var span = span_txt.parentNode ;
  span.parentNode.removeChild(span) ;
  var parent = this.a.parentNode ;
  this.aa = document.createElement("a") ;
  this.aa.href = a.href ;
  this.aa.innerHTML = "<span>"+t+"</span>" ;
  this.aa.style.paddingLeft = "0px" ;
  a.parentNode.insertBefore(this.aa, this.a.nextSibling) ;
  document.addEventListener("DOMAttrModified", this, false) ;
}

DirectLink_v2.prototype.handleEvent = function(event)
{
  if(event.type == "DOMAttrModified" && event.target==this.a && event.attrName.toLowerCase()=="href")
    this.aa.href = event.newValue ;
}

// vim:tw=0:smartindent