-
-
Save ne-sachirou/833567 to your computer and use it in GitHub Desktop.
// @author = http://c4se.sakura.ne.jp/profile/ne.html | |
// @date = 2011-02-23 | |
// @site = https://gist.github.com/833567 | |
// @license = public domain | |
var COMMANDS_LIST = { | |
open: 'open', | |
o: 'open', | |
url: 'open url', | |
view: 'view', | |
v: 'view', | |
home: 'view home', | |
user: 'view user', | |
retweet: 'retweet', | |
rt: 'retweet', | |
reply: 'reply', | |
r: 'reply', | |
'@': 'reply', | |
quotetweet: 'reply quote', | |
qt: 'reply quote', | |
mrt: 'reply mrt', | |
settings: 'settings', | |
setting: 'settings', | |
'set': 'settings', | |
gettings: 'settings', | |
getting: 'settings', | |
'get': 'settings' | |
}; | |
//PreSendUpdateStatus Event Handler | |
function PreSendUpdateStatus(status) { | |
var azvim, flag = false; | |
try { | |
if (/^:/.test(status.text)) { | |
flag = true; | |
azvim = new AzureaVim(status); | |
azvim.run(); | |
TextArea.text = ''; | |
TextArea.in_reply_to_status_id = 0; | |
} | |
} catch (e) { | |
System.alert(e.name + ':\n' + e.message); | |
flag = true; | |
} | |
return flag; | |
} | |
function _focusInput(status_id) { | |
TextArea.text = ':'; | |
TextArea.in_reply_to_status_id = status_id; | |
TextArea.show(); | |
TextArea.setFocus(); | |
TextArea.setCursor(1); | |
} | |
System.addKeyBindingHandler(0xBA, // VK_OEM_1 (:) | |
0, _focusInput); | |
System.addContextMenuHandler(':vim', 0, _focusInput); | |
function _pearse(text) { // @reply String: | |
// @return Array: | |
var command = [], match, regex = /[^\s"]+|\s+|"[^\\"]*(?:\\.[^\\"]*)*"/g; //" | |
text = text.replace(/^\s+|\s+$/g, ''); | |
while (match = regex.exec(text)) { | |
if (!/^\s/.test(match[0])) { | |
command.push(match[0].replace(/^"|"$/g, '')); | |
} | |
} | |
return command; | |
} | |
function _expandTemplate(template, // String: | |
view) { // Object: | |
// String: has Number [cursor] property | |
var cursor, | |
text = template.replace(/#{([^}]+?)}/g, function() { | |
with (view) { | |
return eval(arguments[1]); | |
} | |
}); | |
text = text.split('#{}'); | |
if (text.length === 1) { | |
cursor = 0; | |
text = text[0]; | |
} else { | |
cursor = text[0].length; | |
text = text.join(''); | |
} | |
text.cursor = cursor; | |
return { | |
'text': text, | |
'cursor': cursor | |
}; | |
} | |
//AzureaVim Class | |
function AzureaVim(status) { //@param StatusUpdate Object: | |
this.command_text = status.text.slice(1); | |
this.command = _pearse(this.command_text); | |
this.status_id = status.in_reply_to_status_id; | |
this.screen_name = TwitterService.status.get(this.status_id).user.screen_name; | |
this.status_text = TwitterService.status.get(this.status_id).text; | |
this.status_urls = []; | |
this.status_hashes = []; | |
this.status_users = []; | |
TwitterService.status.getUrls(this.status_id, this.status_urls); | |
TwitterService.status.getHashes(this.status_id, this.status_hashes); | |
TwitterService.status.getUsers(this.status_id, this.status_users); | |
} | |
AzureaVim.commands_list = COMMANDS_LIST; | |
AzureaVim.prototype.run = function() { | |
var command = COMMANDS_LIST[this.command[0]]; | |
if (/ /.test(command)) { | |
this.command.shift(); | |
this.command = command.split(' ').concat(this.command); | |
} else { | |
this.command[0] = command; | |
} | |
this[this.command[0]](); | |
} | |
AzureaVim.prototype.open = function() { | |
var url, | |
c1 = { | |
status: 'status', | |
favstar: 'favstar', | |
fav: 'favstar', | |
f: 'favstar', | |
favotter: 'favotter', | |
favlook: 'favlook', | |
twistar: 'twistar', | |
favolog: 'favolog', | |
twilog: 'twilog', | |
user: 'user', | |
url: 'url' | |
}; | |
switch (c1[this.command[1]]) { | |
case 'status': | |
url = 'https://twitter.com/' + this.screen_name + '/status/' + this.status_id; | |
break; | |
case 'favstar': | |
url = 'http://favstar.fm/t/' + this.status_id; | |
break; | |
case 'favotter': | |
url = 'http://favotter.net/status.php?id=' + this.status_id; | |
break; | |
case 'favlook': | |
url = 'http://favlook.osa-p.net/status.html?status_id=' + this.status_id; | |
break; | |
case 'twistar': | |
url = 'http://twistar.cc/' + this.screen_name + '/status/' + this.status_id; | |
break; | |
case 'favolog': | |
url = 'http://favolog.org/' + this.screen_name; | |
break; | |
case 'twilog': | |
url = 'http://twilog.org/' + this.screen_name; | |
break; | |
case 'user': | |
url = 'http://twitter.com/' + this.screen_name; | |
break; | |
case 'url': | |
if (!this.command[2]) { | |
this.command[2] = 0; | |
} | |
url = this.status_urls[this.command[2]]; | |
break; | |
default: | |
url = this.status_urls[0] || 'https://twitter.com/' + this.screen_name + '/status/' + this.status_id; | |
break; | |
} | |
System.openUrl(url); | |
} | |
AzureaVim.prototype.view = function() { | |
var c1 = { | |
home: 'home', | |
timeline: 'home', | |
h: 'home', | |
mention: 'mention', | |
reply: 'mention', | |
r: 'mention', | |
m: 'mention', | |
'@': 'mention', | |
message: 'message', | |
dm: 'message', | |
d: 'message', | |
user: 'user', | |
u: 'user', | |
favorite: 'favorite', | |
fav: 'favorite', | |
f: 'favorite', | |
following: 'following', | |
follow: 'following', | |
followers: 'followers', | |
follower: 'followers', | |
followed: 'followers' | |
}, | |
views = System.apiLevel >= 11 ? System.views : System; | |
switch (c1[this.command[1]]) { | |
case 'home': | |
views.openTimeline(); | |
break; | |
case 'mention': | |
views.openMention(); | |
break; | |
case 'message': | |
views.openMessage(); | |
break; | |
case 'user': | |
views.openUserTimeline(this.command[2] || this.screen_name, false); | |
break; | |
case 'search': | |
views.openSearch(this.command[2], false); | |
break; | |
case 'favorite': | |
views.openFavorite(); | |
break; | |
case 'match': | |
views.openMatch(this.command[2], false); | |
break; | |
case 'following': | |
views.openFollwoing(); | |
break; | |
case 'followers': | |
views.openFollowers(); | |
break; | |
default: | |
break; | |
} | |
} | |
AzureaVim.prototype.retweet = function() { | |
TwitterService.retweet.create(this.status_id); | |
} | |
AzureaVim.prototype.reply = function() { | |
var c1 = { | |
template: 'template', | |
all: 'all', | |
quote: 'quote', | |
qt: 'quote', | |
mrt: 'mrt', | |
masirosiki: 'mrt' | |
}, | |
t; | |
switch (c1[this.command[1]]) { | |
case 'template': | |
t = _expandTemplate(this.command[2], this); | |
Http.sendRequestAsync('http://google.com/', false, | |
new Function("TextArea.text = '" + t.text.replace("'", "\\'") + "';" + | |
"TextArea.in_reply_to_status_id = '" + (this.command[3] === 'true' ? this.status_id : 0) + "';" + | |
"TextArea.show();" + | |
"TextArea.setFocus();" + | |
"TextArea.setCursor(" + t.cursor + ");")); | |
break; | |
case 'all': | |
this.command = ['reply', 'template', "@#{screen_name + (status_users.length ? ' @' +status_users.join(' @') : '')} #{}", 'true']; | |
this.reply(); | |
break; | |
case 'quote': | |
this.command = ['reply', 'template', "@#{screen_name} #{} RT: #{status_text}", 'true']; | |
this.reply(); | |
break; | |
case 'mrt': | |
this.command = ['reply', 'template', "#{} MRT: #{'http://twitter.com/' + screen_name + '/' + status_id}", 'false']; | |
this.reply(); | |
break; | |
default: | |
this.command = ['reply', 'template', "@#{screen_name} #{}#{status_hashes.length ? ' ' + status_hashes.join(' ') : ''}", 'true']; | |
this.reply(); | |
break; | |
} | |
} | |
AzureaVim.prototype.settings = function() { | |
var figure, value; | |
//if (/^(?:switch)$/.test(this.command[1])) { | |
// figure = this.command.slice(2).join(''); | |
//} else { | |
figure = this.command.slice(1).join(''); | |
//} | |
figure = figure.split('::'); | |
figure = [figure[0]].concat(figure[1].split('=')); | |
if (/^get/.test(this.command[0])) { | |
figure.length = 2; | |
} | |
//switch (this.command[1]) { | |
//case 'switch': | |
// value = System.settings.getValue(figure[0], figure[1]); | |
// if (value === '0') { | |
// System.settings.setValue(figure[0], figure[1], '1'); | |
// System.showNotice('Setting switched: ' + figure[0] + '::' + figure[1] + '=true'); | |
// } else if (value === '1') { | |
// System.settings.setValue(figure[0], figure[1], '0'); | |
// System.showNotice('Setting switched: ' + figure[0] + '::' + figure[1] + '=false'); | |
// } else { | |
// System.showNotice('Setting cannot switch: ' + figure[0] + '::' + figure[1]); | |
// } | |
// break; | |
//default: | |
if (figure[2]) { | |
System.settings.setValue(figure[0], figure[1], figure[2]); | |
System.showNotice('Setting done: ' + figure[0] + '::' + figure[1] + '=' + figure[2]); | |
} else { | |
System.showNotice('Getting done: ' + figure[0] + '::' + figure[1] + '=' + System.settings.getValue(figure[0], figure[1])); | |
} | |
// break; | |
//} | |
//System.settings.reconfigure(); | |
} | |
////test | |
//:settings Misc :: FontSize = 10 | |
//:settings Misc::EnableAutoRefresh=1 | |
function _attachNewCommands() { | |
var path = System.applicationPath.replace(/[^\\]+$/, 'Scripts\\AzureaVim'), | |
fso = new ActiveXObject('Scripting.FileSystemObject'), | |
files = new Enumerator(fso.GetFolder(path).Files); | |
for (; !files.atEnd(); files.moveNext()) { | |
try { | |
if (/\.js$/.test(files.item().Name)) { | |
eval(fso.OpenTextFile(path + '\\' + files.item().Name, 1).ReadAll()); | |
} | |
} catch (e) {} | |
} | |
} | |
try { | |
_attachNewCommands(); | |
} catch (e) {} |
https://gist.github.com/833567/99c80580593b8b0f667f14f143bf11fecc92738d
AzureaWin、リプライ拡張 #js #AzureaScript - c4se記:さっちゃんですよ☆ http://d.hatena.ne.jp/Kureduki_Maari/20110129/1296267611 の機能を統合。:rtコマンドと:replyコマンドを追加。
:rtコマンドは、ReTweetするのみ。
:replyコマンドは、templateを取って展開する内部動作とし、拡張を容易とした。各種短縮コマンドを追加。
_pearse関数を:replyに合わせて拡張(内部動作)。
:reply template部分のコードは、可能であれば将来に改善する事(TODO)。
https://gist.github.com/833567/3fa34716153928fd5b8b8ea85dc39f8b9a79b1b4
:translateコマンドを、非同期へ書き直した。
:replyコマンド部分の誤字修正 s/masirisiki/masirosiki/
https://gist.github.com/833567/f04cab61135d06d8845542d253808f4306dde826
:settingsコマンドを追加。:settings Misc::EnableAutoRefresh=1 の様に設定し、:settings Misc::EnableAutoRefreshの様に取得する。各種短縮コマンドを追加。
プラグインを取得可能にした。Scripts/AzureaVim下のjsを、起動時に読み込む。ActiveXObjectが有効に成っている必要が有る(無効の場合、単純に読み込まれない)。
上記に合わせ、:shindanコマンドと:translateコマンドを、本体から外した。
AzureaVim変更点 #AzureaScript #js - c4se記:さっちゃんですよ☆ http://d.hatena.ne.jp/Kureduki_Maari/20110225/1298622144 変更点解説記事
ne-sachirou/AzureaVim - GitHub https://github.com/ne-sachirou/AzureaVim にprojectを移動
https://gist.github.com/833567/e6e5f1146ab605b050fd26d44bf1aac06aa43703
コマンドの追加を簡易化。短縮コマンドには、prototype関数を作らなくて良い様にした。例えば、'b': 'a x',と空白を入れて書けば、:b yは:a x yと同義に成る。
:viewコマンドを追加。Azurea内のviewを移動する。API Level10, API Level11に対応 (line 238)。各種短縮コマンドも追加。:userコマンドは、:view userに吸収。
:openコマンドのオプション管理を、Hashにして簡易化。
:shindanコマンドを追加。指定したtweetの診断メーカーをリクエストし、投稿欄に結果を入力(tweet自動送信はしない)。 (by https://gist.github.com/831901 )