By Cathy Mullican
Has 1 other script.
// ==UserScript==
// @name link titler
// @description fetch linked page and show the title in tooltip.
// @include *
// @exclude http://google.com/*
// @exclude http://*.google.com/*
// @exclude http://yahoo.com/*
// @exclude http://*.yahoo.com/*
// @exclude http://altavista.com/*
// @exclude http://*.altavista.com/*
// ==/UserScript==
var replacements, regex, key;
replacements = {
'>': '>',
'<': '<',
'"': '"',
''': "'",
'&': '&',
' ': ' ',
'¡': '¡',
'¤': '¤',
'¢': '¢',
'£': '£',
'¥': '¥',
'¦': '¦',
'§': '§',
'¨': '¨',
'©': '©',
'ª': 'ª',
'«': '«',
'¬': '¬',
'­': '­',
'®': '®',
'™': '™',
'¯': '¯',
'°': '°',
'±': '±',
'²': '²',
'³': '³',
'´': '´',
'µ': 'µ',
'¶': '¶',
'·': '·',
'¸': '¸',
'¹': '¹',
'º': 'º',
'»': '»',
'¼': '¼',
'½': '½',
'¾': '¾',
'¿': '¿',
'×': '×',
'÷': '÷',
'À': 'À',
'Á': 'Á',
'Â': 'Â',
'Ã': 'Ã',
'Ä': 'Ä',
'Å': 'Å',
'Æ': 'Æ',
'Ç': 'Ç',
'È': 'È',
'É': 'É',
'Ê': 'Ê',
'Ë': 'Ë',
'Ì': 'Ì',
'Í': 'Í',
'Î': 'Î',
'Ï': 'Ï',
'Ð': 'Ð',
'Ñ': 'Ñ',
'Ò': 'Ò',
'Ó': 'Ó',
'Ô': 'Ô',
'Õ': 'Õ',
'Ö': 'Ö',
'Ø': 'Ø',
'Ù': 'Ù',
'Ú': 'Ú',
'Û': 'Û',
'Ü': 'Ü',
'Ý': 'Ý',
'Þ': 'Þ',
'ß': 'ß',
'à': 'à',
'á': 'á',
'â': 'â',
'ã': 'ã',
'ä': 'ä',
'å': 'å',
'æ': 'æ',
'ç': 'ç',
'è': 'è',
'é': 'é',
'ê': 'ê',
'ë': 'ë',
'ì': 'ì',
'í': 'í',
'î': 'î',
'ï': 'ï',
'ð': 'ð',
'ñ': 'ñ',
'ò': 'ò',
'ó': 'ó',
'ô': 'ô',
'õ': 'õ',
'ö': 'ö',
'ø': 'ø',
'ù': 'ù',
'ú': 'ú',
'û': 'û',
'ü': 'ü',
'ý': 'ý',
'þ': 'þ',
'ÿ': 'ÿ',
'Œ': 'Œ',
'œ': 'œ',
'Š': 'Š',
'š': 'š',
'Ÿ': 'Ÿ',
'ˆ': 'ˆ',
'˜': '˜',
' ': ' ',
' ': ' ',
' ': ' ',
'‌': '‌',
'‍': '‍',
'‎': '‎',
'‏': '‏',
'–': '–',
'—': '—',
'‘': '‘',
'’': '’',
'‚': '‚',
'“': '“',
'”': '”',
'„': '„',
'†': '†',
'‡': '‡',
'…': '…',
'‰': '‰',
'‹': '‹',
'›': '›',
'€': '€'
};
regex = {};
for (key in replacements) {
regex[key] = new RegExp(key, 'g');
}
var allLinks = document.evaluate('//a[@href]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
var thisSite = window.location.host;
var thisDomain = thisSite.match(/((\w+\.\w+)(\.\w\w)?)$/)[1];
for (var i = 0; i < allLinks.snapshotLength; i++){
var thisLink = allLinks.snapshotItem(i);
if (thisLink.href.search(thisDomain) < 0
&& thisLink.href.search(/^http:/) >= 0
//&& (!thisLink.href.search(/\?/) || thisLink.href.search(/amazon|youtube/))
)
{
setTitle(thisLink, thisLink.href);
}
}
function setTitle(elem, url) {
var old_title = elem.getAttribute('title');
elem.setAttribute('title', 'Please wait ...');
GM_xmlhttpRequest({
method:'GET',
url: url,
headers: {'User-Agent': 'Mozilla/4.0 (compatible) Greasemonkey'},
onerror:function(responseDetails) {
elem.setAttribute('title', 'An error occured: ' + responseDetails.status + ': ' + responseDetails.status_text);
},
onload:function(responseDetails) {
var dest_title;
var myText = responseDetails.responseText.replace(/[\n\r\f]/g, ' ');
if (myText.search(/<\s*title\s*>.*<\s*\/title/i) >= 0)
{
dest_title = myText.match(/<\s*title\s*>(.*)<\s*\/title/i)[1];
if (dest_title == null || dest_title == '')
{
dest_title = 'Empty title';
}
else
{
if (old_title != null && old_title.search(/\S+/) >= 0)
{
dest_title = dest_title + ' : ' + old_title;
}
for (key in replacements) {
dest_title = dest_title.replace(regex[key], replacements[key]);
}
while (dest_title.match(/&#(\d+);/))
{
var thisChar = RegExp.$1;
var coded = new RegExp("&#"+thisChar+";", 'g');
var uncoded = String.fromCharCode(thisChar);
dest_title = dest_title.replace(coded, uncoded);
}
while (dest_title.match(/&#x([\da-f]+);/i))
{
var thisChar = RegExp.$1;
var coded = new RegExp("&#x"+thisChar+";", 'g');
var uncoded = String.fromCharCode(parseInt(thisChar, 16));
dest_title = dest_title.replace(coded, uncoded);
}
}
elem.setAttribute('title', dest_title);
}
else
{
elem.setAttribute('title', 'No title tags');
}
}
});
}