Created
February 18, 2011 11:42
-
-
Save ne-sachirou/833567 to your computer and use it in GitHub Desktop.
AzureaVim.js #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-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) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AzureaVim変更点 #AzureaScript #js - c4se記:さっちゃんですよ☆ http://d.hatena.ne.jp/Kureduki_Maari/20110225/1298622144 変更点解説記事
ne-sachirou/AzureaVim - GitHub https://github.com/ne-sachirou/AzureaVim にprojectを移動