Link Tooltips

Adds and/or modifies link and image title attributes to include more informaton

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        Link Tooltips
// @namespace   Cromagnon
// @description Adds and/or modifies link and image title attributes to include more informaton
// @include     *
// @version     1.2.0202
// ==/UserScript==



//go through and add or modify each link's title
//
//  !Link.title -> Link.href
//
//  !Link.href
//
//       Link.title -> unchanged
//
//   Link.href = #
//
//       Link.title -> unchanged
//
//   Link.title -> Link.title + ( Link.href )
//
//   !Img.title
//
//       !Img.alt
//
//          Img.title -> Link.title
//
//       !Link.href
//
//          Img.title -> Img.alt
//
//        Link.href = #
//
//          Img.title -> Img.alt
//
//        Img.title -> Img.alt + ( Link.href )
//
//   !Link.href
//
//      Img.title -> unchanged
//
//    Link.href = #
//
//      Img.title -> unchanged
//
//    Img.title -> Img.title + ( Link.href )
//
//
function checkLinkTitles(e) {

  var target = (e == null) ? document : e.target;
  
  var links = target.getElementsByTagName("a");
  
  if (links.length == 0) {
  
      if (target.nodeName != "A") return;
      
      links = [];
      links.push(target);

  };
  
  for (var i = 0; link = links[i]; ++i) {
  
    //if (link.getAttribute("modified-by") == "Link Tooltips")  continue;
    
    //link.setAttribute("modified-by", "Link Tooltips");
    
    var href = link.getAttribute("href");
    var title = link.getAttribute("title");
    
    if (!title) {
    
        if (href != null) link.setAttribute("title", href);
    
    } else if ((href != null) && (href != "#")) {

        if ((title != href) && (title.indexOf("(" + href + ")") == -1))
	
	    link.setAttribute("title", title + "\n (" + href + ")");
    };


    //in the latest FireFox versions, titles on image elements override those on enclosing links
    
    var imgs = link.getElementsByTagName("img");
    
    for(var j = 0; img = imgs[j]; ++j) {
    
      var title = img.getAttribute("title");
      var alt = img.getAttribute("alt");
      
      if (!title) {
      
	if (!alt)
	
	    img.setAttribute("title", link.getAttribute("title"));
	    
	else if ((href != null) && (href != "#"))
	
	    img.setAttribute("title", alt + "\n (" + href + ")");
	    
	else img.setAttribute("title", alt);
      }
      else if ((href != null) && (href != "#")) {
      
          if ((title != href) && (title.indexOf("(" + href + ")") == -1))
      
	    img.setAttribute("title", title + "\n (" + href + ")");
      }
    }
  }
};



// Main function
//
function init() {

    checkLinkTitles();

    document.addEventListener("DOMSubtreeModified", checkLinkTitles, false);

};



// Call our main function.
//

init();

//end