This little script generates links from usernames and hashtags to Twitter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tuitlink | |
* by Alberto Mtnz (https://github.com/threkk/scripts) | |
* This little script generates links from usernames and hashtags to Twitter. | |
* To use it, just import the library: | |
* <script type="text/javascript" src="twitlink.js"></script> | |
* It is under a MIT license. | |
* | |
*/ | |
/*jslint browser:true */ | |
var tuitlink = { | |
load : function () { | |
'use strict'; | |
var body, username, hashtags; | |
username = /\s@[a-zA-Z0-9_]{1,15}/g; | |
hashtags = /\s#[a-zA-Z0-9_]+/g; | |
body = document.body.innerHTML; | |
body = body.replace(username, this.users); | |
body = body.replace(hashtags, this.htags); | |
document.body.innerHTML = body; | |
}, | |
users : function (match) { | |
'use strict'; | |
var m, r; | |
m = match.slice(2, match.lenght); | |
r = " <a href='http://twitter.com/" + m + " '>" + match + "</a>"; | |
return r; | |
}, | |
htags : function (match) { | |
'use strict'; | |
var m, r; | |
m = match.slice(2, match.length); | |
r = " <a href='http://twitter.com/search?q=%23" + m + " '>" + match + "</a>"; | |
return r; | |
} | |
}; | |
window.onload = function () { | |
'use strict'; | |
tuitlink.load(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment