Link Tooltips

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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