Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created August 15, 2010 05:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hitode909/525140 to your computer and use it in GitHub Desktop.
hint-favorite.tw
/*
twittperator.jsのプラグインです.
Hintからstatusをfavoriteできます.
== Settings ==
g:twittperator_plugin_hint_favorite = 1
g:hint_favorite_key = 'f'
g:hint_favorite_xpath = '//a[contains(@href, "status" )]'
*/
(function () {
let hintKey = liberator.globalVariables.hint_favorite_key || 'f';
let hintXPath = liberator.globalVariables.hint_favorite_xpath || '//a[contains(@href, "status" )]';
hints.addMode(
hintKey,
'Favorite a Twitter status',
function (elem) {
if (!elem.href.match(new RegExp("/status(?:es)?/(\\d+)")))
throw("Failed to extract status id.");
let id = RegExp.$1;
let OAuth = plugins.twittperator.OAuth;
let Util = { // XXX: 公開されてなかったからコピペ
fixStatusObject: function (st) {
function unescapeBrakets(str)
str.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
let result = {};
for (let [n, v] in Iterator(st)) {
result[n] = v && typeof v === 'object' ? Util.fixStatusObject(v) :
n === 'text' ? unescapeBrakets(v) :
v;
}
return result;
}
};
OAuth.post("http://api.twitter.com/1/favorites/create/" + id + ".json", null, function(text) {
let res = Util.fixStatusObject(JSON.parse(text.responseText || text)); // XXX: textがxhrのときとresponseTextのときがある
if (res.error) {
liberator.echoerr("[Twittperator] fav: " + res.error);
return;
}
liberator.echo("[Twittperator] fav: " + res.user.name + " " + res.text);
});
},
function () hintXPath
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment