Skip to content

Instantly share code, notes, and snippets.

@ebith
Created August 1, 2010 20:21
Show Gist options
  • Save ebith/503723 to your computer and use it in GitHub Desktop.
Save ebith/503723 to your computer and use it in GitHub Desktop.
StreamをGrowlで通知するTwittperatorプラグイン
/*
* Please write the below line into .vimperatorrc.
* let g:twittperator_plugin_notify_growl = 1
* let g:twittperator_screen_name = "YOUR_SCREEN_NAME"
* let g:twittperator_plugin_notify_growl_ng_words = "NG|WORDS"
*/
(function () {
let screenName = liberator.globalVariables.twittperator_screen_name;
let ngWords = liberator.globalVariables.twittperator_plugin_notify_growl_ng_words || '(?!)';
let send;
let log = liberator.log;
//日本語でフィルタかけるための正規表現(http://twitter.com/#!/anekos/status/28576983431)
let JP = new RegExp("[\\u4e00-\\u9fa0\\u30A1-\\u30F6\\u30FC\\u3042-\\u3093\\u3001\\u3002\\uFF01\\uFF1F]");
//TwitterFoxEnhancerから(http://d.hatena.ne.jp/snaka72/20090720/1248115649)
const Growler = (function () {
if (navigator.platform == 'Win32') {
let growl = Components.classes['@growlforwindows.com/growlgntp;1'].getService().wrappedJSObject;
growl.register(
'Twittperator',
"http://s.twimg.com/a/1280528898/images/default_profile_0_normal.png",
[{name: 'notify', displayName: 'notify'}, {name: 'mention',displayName: 'mention'}]);
return {
notify: function (title, text, iconURL) {
growl.notify('Twittperator', 'notify', title, text, iconURL);
},
mention: function (title, text, iconURL) {
growl.notify('Twittperator', 'mention', title, text, iconURL);
}
};
}
else {
let alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);
return {
notify: function (title, text, iconURL) {
alertService.showAlertNotification(iconURL, title, text);
},
mention: function (title, text, iconURL) {
alertService.showAlertNotification(iconURL, title, text);
}
};
}
return {
notify: function () {},
mention: function () {}
};
})();
let sendGrowl = function(msg, JPcheck) {
if (msg.user && msg.text && msg.user.screen_name != screenName) {
if (JPcheck) {
if (!JP.test(msg.text)){ return; }
}
if (RegExp(ngWords, 'i').test(msg.text)){ return; }
if (send == msg.id){ return; } else { send = msg.id; }
let message = eval(uneval(msg.text));
if (msg.entities.urls[0]) {
for ( let i in msg.entities.urls) {
message = message.replace(msg.entities.urls[i].url, msg.entities.urls[i].expanded_url);
}
}
if (~msg.text.indexOf(screenName) || msg.in_reply_to_screen_name == screenName) {
Growler.mention(msg.user.screen_name, message, msg.user.profile_image_url);
}
else {
Growler.notify(msg.user.screen_name, message, msg.user.profile_image_url);
}
}
}
plugins.twittperator.ChirpUserStream.addListener(
function onMsg(msg, raw) {
sendGrowl(msg, 0);
}
);
plugins.twittperator.TrackingStream.addListener(
function onMsg(msg, raw) {
sendGrowl(msg, 1);
}
);
})();
// vim: sw=2 ts=2 et fdm=marker ft=javascript:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment