hint-favorite.tw
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
/* | |
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(/</g, "<").replace(/>/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