Skip to content

Instantly share code, notes, and snippets.

@ba3r
Created December 2, 2009 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ba3r/246967 to your computer and use it in GitHub Desktop.
Save ba3r/246967 to your computer and use it in GitHub Desktop.
var noun_type_twitter_username = {
label: "user",
rankLast: true,
noExternalCalls: true,
cacheTime: 0,
suggest: function nt_twuser_suggest(text, html, cb, selected) {
if (!text || selected)
return [];
var foundAt = text[0] === '@';
if (foundAt) text = text.slice(1);
var suggs = CmdUtils.grepSuggs(text, this.logins());
if (/\w*/.test(text))
suggs.push(CmdUtils.makeSugg(text, null, {}, 0.5));
if (foundAt)
suggs = [{
__proto__: s,
text: '@' + s.text,
html: '@' + s.html,
summary: '@' + s.summary,
score: Math.pow(s.score, 0.8),
} for each (s in suggs)];
return suggs;
},
logins: function nt_twuser_logins(reload) {
if (this._list && !reload) return this._list;
var list = [];
var token = (Cc["@mozilla.org/security/pk11tokendb;1"]
.getService(Ci.nsIPK11TokenDB)
.getInternalKeyToken());
if (!token.needsLogin() || token.isLoggedIn()) {
// Look for twitter usernames stored in password manager
var usersFound = {};
var passwordManager = (Cc["@mozilla.org/login-manager;1"]
.getService(Ci.nsILoginManager));
for each (let url in ["https://twitter.com", "http://twitter.com"]) {
for each (let login in passwordManager.findLogins({}, url, "", "")) {
let {username} = login;
if (username in usersFound) continue;
usersFound[username] = true;
list.push(CmdUtils.makeSugg(username, null, login));
}
}
}
return this._list = list;
},
_list: null,
};
/* Twitter User v0.65b */
var t = "http://twitter.com/";
CmdUtils.CreateCommand({
names: ["twtuser", "twitter timeline"],
icon: "chrome://ubiquity/skin/icons/twitter.ico",
description: "Opens the Twitter timeline of the selected user.",
help: "Type a twitter user name and hit Enter to get to his/her twitter feed. The preview shows the user's avatar and some links to followers etc. Also works with @username.",
author: {name: "Michael Baer", homepage: "http://twitter.com/synapsos"},
license: "GPL",
homepage: "http://twitter.com",
arguments: [{role: 'object', nountype: noun_type_twitter_username, label: "username"}],
preview: function preview(pblock, args) {
var u = args.object.text;
u = u.replace(/(ä|æ)/gi, "ae");
u = u.replace(/(ö|œ)/gi, "oe");
u = u.replace(/ü/gi, "ue");
u = u.replace(/ß/g, "ss");
u = u.replace(/(á|à|â)/gi, "a");
u = u.replace(/(é|è|ê|ë)/gi, "e");
u = u.replace(/(í|ì|î|ï)/gi, "i");
u = u.replace(/(ó|ò|ô)/gi, "o");
u = u.replace(/(ú|ù|û)/gi, "u");
u = u.replace(/(ñ)/gi, "n");
u = u.replace(/(ç)/gi, "c");
u = u.replace(/(\.|\-)/, "_");
u = u.replace(/\W/gi, "");
u = u.replace(/\s/g, "");
var p = t + u;
pblock.innerHTML =
"<style type='text/css'>img { float: left; margin: 15px; border: 0px; height: 48px;} a {text-decoration:none;} </style>"
+ "<a href='" + p + "'>"
+ "<img src='http://michaelbaer.kilu.de/" + u + "' />"
+ "<h2>" + u + "</a></h2>"
+ "<a href='" + p + "/following'>following</a> | "
+ "<a href='" + p + "/followers'>followers</a> | "
+ "<a href='" + p + "/lists'>lists</a> | ";
if (u == "") {
pblock.innerHTML += "<a href='" + t + "'>homepage</a>";
} else {
pblock.innerHTML += "<a href='" + t + "#search?q=@" + u + "'>mentions</a> || "
+ "<a href='" + t + "?status=@"+ u + "'>@" + u + "</a>";
}
},
execute: function execute(args) {
var u = args.object.text;
u = u.replace(/(ä|æ)/gi, "ae");
u = u.replace(/(ö|œ)/gi, "oe");
u = u.replace(/ü/gi, "ue");
u = u.replace(/ß/g, "ss");
u = u.replace(/(á|à|â)/gi, "a");
u = u.replace(/(é|è|ê|ë)/gi, "e");
u = u.replace(/(í|ì|î|ï)/gi, "i");
u = u.replace(/(ó|ò|ô)/gi, "o");
u = u.replace(/(ú|ù|û)/gi, "u");
u = u.replace(/(ñ)/gi, "n");
u = u.replace(/(ç)/gi, "c");
u = u.replace(/(\.|\-)/, "_");
u = u.replace(/\W/gi, "");
u = u.replace(/\s/g, "");
Utils.openUrlInBrowser(t + u);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment