aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsuVene2008-12-28 21:09:43 +0000
committersuVene2008-12-28 21:09:43 +0000
commit6e4b0f41b4cb636164d040133f434db44e568a9e (patch)
tree81403f0ea2a309b2c77312fa50295a80e1bba19e
parent926c1e175ff6ca3fdbb86f531885d05dc0895d60 (diff)
downloadvimperator-plugins-6e4b0f41b4cb636164d040133f434db44e568a9e.tar.bz2
add notifier/subject_wassr.js
mod libly.js bugfix. etc. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@27534 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--_libly.js6
-rw-r--r--notifier.js18
-rwxr-xr-xnotifier/subject_wassr.js72
3 files changed, 89 insertions, 7 deletions
diff --git a/_libly.js b/_libly.js
index b77b9e5..259ec11 100644
--- a/_libly.js
+++ b/_libly.js
@@ -12,7 +12,7 @@ var PLUGIN_INFO =
<description lang="ja">適当なライブラリっぽいものたち。</description>
<author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
<license>MIT</license>
- <version>0.1.15</version>
+ <version>0.1.16</version>
<minVersion>1.2</minVersion>
<maxVersion>2.0pre</maxVersion>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/_libly.js</updateURL>
@@ -384,8 +384,9 @@ libly.Request.prototype = {
try {
libly.Request.requestCount++;
+ this.method = method;
this.transport = new XMLHttpRequest();
- this.transport.open(method, this.url, this.options.asynchronous);
+ this.transport.open(method, this.url, this.options.asynchronous, this.options.username, this.options.password);
this.transport.onreadystatechange = libly.$U.bind(this, this._onStateChange);
this.setRequestHeaders();
@@ -452,7 +453,6 @@ libly.Request.prototype = {
for (let name in headers)
this.transport.setRequestHeader(name, headers[name]);
-
},
get: function() {
this._request('GET');
diff --git a/notifier.js b/notifier.js
index d7ca379..7028d7a 100644
--- a/notifier.js
+++ b/notifier.js
@@ -11,7 +11,7 @@ var PLUGIN_INFO =
<description>change notice framework.</description>
<description lang="ja">変更通知フレームワーク。</description>
<author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
- <version>0.1.4</version>
+ <version>0.1.5</version>
<license>MIT</license>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
@@ -237,11 +237,13 @@ function bootstrap() {
var SubjectHttp = Subject;//{{{
$U.extend(SubjectHttp.prototype, {
initialize: function() {
+ this.preInitialized = true;
this.initialized = false;
this.count = 0;
this.cache;
- if (typeof this.preInitialize == 'function') this.preInitialize();
+ if (typeof this.preInitialize == 'function') this.preInitialized = this.preInitialize();
+ if (!this.preInitialized) return;
var req = new libly.Request(
this.options.url,
@@ -254,7 +256,12 @@ function bootstrap() {
if (this.cache)
this.initialized = true;
}));
- req.get();
+ req.addEventListener('onFailure', function(res) { logger.log(res); });
+ req.addEventListener('onException', function(res) { logger.log(res); });
+ if (this.method == 'POST')
+ req.post();
+ else
+ req.get();
},
check: function() {
if (!this.initialized) return;
@@ -280,7 +287,10 @@ function bootstrap() {
}
}
}));
- req.get();
+ if (this.method == 'POST')
+ req.post();
+ else
+ req.get();
},
diff: function(cache, parsed) cache
});//}}}
diff --git a/notifier/subject_wassr.js b/notifier/subject_wassr.js
new file mode 100755
index 0000000..5e70752
--- /dev/null
+++ b/notifier/subject_wassr.js
@@ -0,0 +1,72 @@
+/*** BEGIN LICENSE BLOCK {{{
+ Copyright (c) 2008 suVene<suvene@zeromemory.info>
+
+ distributable under the terms of an MIT-style license.
+ http://www.opensource.jp/licenses/mit-license.html
+}}} END LICENSE BLOCK ***/
+// PLUGIN_INFO//{{{
+var PLUGIN_INFO =
+<VimperatorPlugin>
+ <name>{NAME}</name>
+ <description>Wassr change notice.</description>
+ <description lang="ja">Wassr変更通知。</description>
+ <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
+ <version>0.1.0</version>
+ <license>MIT</license>
+ <minVersion>2.0pre</minVersion>
+ <maxVersion>2.0pre</maxVersion>
+ <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/subject_wassr.js</updateURL>
+</VimperatorPlugin>;
+//}}}
+(function() {
+
+var notifier = liberator.plugins.notifier;
+if (!notifier) return;
+
+var libly = notifier.libly;
+var $U = libly.$U;
+var logger = $U.getLogger('subject_wassr');
+
+var URL = 'http://api.wassr.jp/statuses/friends_timeline.json?id=';
+
+notifier.subject.register(notifier.SubjectHttp, {
+ interval: 60,
+ method: 'POST',
+ options: {
+ url: '',
+ headers: null,
+ extra: {}
+ },
+ preInitialize: function() {
+ [username, password] = $U.getUserAndPassword('http://wassr.jp', 'http://wassr.jp');
+ this.options.url = URL + username + '&page=4';
+ this.options.extra.username = username;
+ this.options.extra.password = password;
+ logger.log(username + ':' + password);
+ return (username && password) ? true : false;
+ },
+ parse: function(res) {
+ if (this.count == 0) return []; // for debug
+ return $U.evalJson(res.responseText) || [];
+ },
+ diff: function(cache, parsed)
+ parsed.filter(function(item)
+ !cache.some(function(c) c.html == item.html)),
+ buildMessages: function(diff) {
+ return diff.map($U.bind(this, function(d) {
+ var html = <div>
+ {d.reply_status_url ? <p><a href={d.reply_status_url}>{'> ' + d.reply_message + ' by ' + d.reply_user_nick}</a></p> : ''}
+ <p>
+ <img src={d.user.profile_image_url} alt={d.user_login_id} width="16" height="16"/>
+ {d.photo_thumbnail_url ? <img src={d.photo_thumbnail_url}/> : ''}
+ {d.html || ''}
+ </p>
+ </div>.toString();
+ return new notifier.Message('Wassr', html, d.link)
+ }));
+ }
+});
+
+})();
+// vim: set fdm=marker sw=4 ts=4 sts=0 et:
+