Skip to content

Instantly share code, notes, and snippets.

@quake
Created February 21, 2009 12:56
Show Gist options
  • Save quake/68031 to your computer and use it in GitHub Desktop.
Save quake/68031 to your computer and use it in GitHub Desktop.
replaceLinkText : function(text) {
text = this._unescapeHTML.unescape(text.replace(/&/g,"&"));
var elem = document.createElement("description");
elem.className = "twitter-notifier-message-body";
var pat = /((http(s?))\:\/\/)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/([\w#!:.?+=&%@~*\';,\-\/\$])*)?/g;
var re = /[.,;:]$/;
while (pat.exec(text) != null) {
var left = RegExp.leftContext;
var url = RegExp.lastMatch;
text = RegExp.rightContext;
if (re.test(url)) {
text = RegExp.lastMatch + text;
url = url.replace(re, '');
}
elem.appendChild(document.createTextNode(left));
var urltext = url;
if (url.length > 27) {
urltext = url.substr(0, 27) + "...";
}
var anchor = this.createAnchorText(url, urltext, true);
elem.appendChild(anchor);
pat.lastIndex = 0;
}
if (text) {
elem.appendChild(document.createTextNode(text));
}
return elem;
},
createAnchorText: function(link, text, doTinyURL) {
var anchor = document.createElement("a");
anchor.className = "twitter-notifier-hyperlink";
anchor.setAttribute("href", link);
anchor.setAttribute("tooltiptext", link);
if (doTinyURL && link.match(this._tinyURL)) {
anchor.setAttribute("onmouseover", "gTwitterNotifier.onHoverTinyURL(this)");
}
anchor.appendChild(document.createTextNode(text));
return anchor;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment