Created
February 20, 2011 00:52
-
-
Save ne-sachirou/835563 to your computer and use it in GitHub Desktop.
短縮URLを伸展する #AzureaScript
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
// @author = http://c4se.sakura.ne.jp/profile/ne.html | |
// @date = 2011-02-25 | |
// @site = https://gist.github.com/835563 | |
// @license = public domain | |
var services = [], | |
cashe = { | |
'http://c4se.tk/': 'http://c4se.sakura.ne.jp/' | |
}; | |
try { | |
Http.sendRequestAsync('http://untiny.me/api/1.0/services/?format=text', false, | |
function(response) { // @param HttpResponce Object: | |
services = response.body.split(', '); | |
}); | |
} catch (e) {} | |
function isPossibleUnshorten(url) { // @param String: shortend URL | |
// @return Boolean: | |
var _services = services, i = -1, is_possible = false; | |
while (_services[++i]) { | |
if (url.indexOf(_services[i]) !== -1) { | |
is_possible = true; | |
break; | |
} | |
} | |
return is_possible; | |
} | |
function unshorten(url, // @param String: shortened URL | |
async) { // @param Boolean=false: | |
// @return String: unshortened URL | |
var _cashe = cashe, response, result = url; | |
if (_cashe[url]) { | |
result = _cashe[url]; | |
} else if (isPossibleUnshorten(url)) { | |
if (!async) { | |
try { | |
response = Http.sendRequest('http://untiny.me/api/1.0/extract/?url=' + url + '&format=text', false); | |
result = /^error/.test(response.body) ? url : response.body; | |
_cashe[url] = result; | |
} catch (e) {} | |
} else { | |
try { | |
Http.sendRequestAsync('http://untiny.me/api/1.0/extract/?url=' + url + '&format=text', false, | |
function(response) { | |
cashe[url] = /^error/.test(response.body) ? url : response.body; | |
}); | |
} catch (e) {} | |
} | |
} | |
return result; | |
} | |
function PreProcessTimelineStatus(status) { // @param Status Object: | |
status.text = status.text.replace(/https?:\/\/[0-9A-Za-z._\-^~\/&%?]+/g, | |
function(url) { | |
return unshorten(url, true); | |
}); | |
} | |
System.addContextMenuHandler('unshorten', 0, | |
function(status_id) { // @param String: | |
var urls = [], i = -1; | |
TwitterService.status.getUrls(status_id, urls); | |
while (urls[++i]) { | |
if (isPossibleUnshorten(urls[i])) { | |
System.inputBox(urls[i], unshorten(urls[i]), false); | |
break; | |
} | |
} | |
}); |
AzureaVim pluginへ統合しました。此ちらのGistは更新しません。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/835563/5ee92fc1d9534d3542365fa2902843d7e240c6e0
デフォルト動作を変更した。PreProcessTimelineStatusでは、新規短縮URLを得た場合、非同期で伸展し、キャッシュに保存する。同じURLを二度目に得た時は、伸展されて表示する。此の変更で、UIは凍結しなく成る。(TODO: AzureaVimの:shindanプラグインは、別途対処する事)