aboutsummaryrefslogtreecommitdiffstats
path: root/notifier/subject_hatelabo_bottle.js
diff options
context:
space:
mode:
authorsuVene2008-12-08 18:04:17 +0000
committersuVene2008-12-08 18:04:17 +0000
commit4012d388f4e4698ac13e30f0d8d3c310cdfe55d5 (patch)
treea5759baaed32f98fefc96af30d3b930d4675e9e8 /notifier/subject_hatelabo_bottle.js
parenta9eaeea1f3d7fdff871a94801d7b278b5def26ba (diff)
downloadvimperator-plugins-4012d388f4e4698ac13e30f0d8d3c310cdfe55d5.tar.bz2
*SubjectHttp定義.
*registerするときに下位クラスから基底クラスを指定するように変更. *notifier/observer/subject の PLUGIN_INFO対応 @see http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/pluginManager.js *ほか. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26152 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'notifier/subject_hatelabo_bottle.js')
-rw-r--r--notifier/subject_hatelabo_bottle.js89
1 files changed, 46 insertions, 43 deletions
diff --git a/notifier/subject_hatelabo_bottle.js b/notifier/subject_hatelabo_bottle.js
index 9c4914d..6c4a330 100644
--- a/notifier/subject_hatelabo_bottle.js
+++ b/notifier/subject_hatelabo_bottle.js
@@ -1,12 +1,17 @@
-/**
- * notifier.js plugin subject
- * @name subject_hatena_bottle.js
- * @description notify if hatena bottle changed.
- * @description-ja はてなボトルの変更通知。
- * @author suVene suvene@zeromemory.info
- * @version 0.1.0
- * Last Change: 08-Dec-2008.
- */
+// PLUGIN_INFO//{{{
+var PLUGIN_INFO =
+<VimperatorPlugin>
+ <name>{name}</name>
+ <description>notifies if hatena bottle was changed.</description>
+ <description lang="ja">はてなボトルの変更通知。</description>
+ <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
+ <version>0.1.0</version>
+ <minVersion>2.0pre</minVersion>
+ <maxVersion>2.0pre</maxVersion>
+ <detail><![CDATA[
+ ]]></detail>
+</VimperatorPlugin>;
+//}}}
(function() {
var notifier = liberator.plugins.notifier;
@@ -17,22 +22,14 @@ var $U = libly.$U;
var logger = $U.getLogger('subject_hatelabo_bottle');
var URL = 'http://bottle.hatelabo.jp';
+//var URL = 'http://localhost/index.html?a';
-notifier.subject.register({
- interval: 30,
- initialize: function() {
- this.count = 0;
- this.initialized = false;
- this.cache;
-
- var req = new libly.Request(URL);
- req.addEventListener('onSuccess', $U.bind(this, function(res) {
- logger.log('initialized');
- this.cache = this.parse(res);
- if (this.cache)
- this.initialized = true;
- }));
- req.get();
+notifier.subject.register(notifier.SubjectHttp, {
+ interval: 40,
+ options: {
+ url: URL,
+ headers: null,
+ extra: null
},
parse: function(res) {
@@ -44,31 +41,37 @@ notifier.subject.register({
if (!dom) return ret;
ret = [];
- for (let i = 0, len < dom.childNodes.length; i < len; i++) {
+ for (let i = 0, len = dom.childNodes.length; i < len; i++) {
ret.push(dom.childNodes[i]);
}
return ret;
},
- check: function() {
-
- if (!this.initialized) return;
-
- this.count++;
- logger.log('check');
- var req = new libly.Request(URL);
- req.addEventListener('onSuccess', $U.bind(this, function(res) {
- var text = res.responseText;
- logger.log('success!! ');
- var message = new notifier.Message('TEST', text);
- this.notify(message);
+ diff: function(cache, parsed) {
+ var ret = [];
+ parsed.forEach(function(element) {
+ if (!cache.some(function(c) { if (c.toString() == element.toString()) return true }))
+ ret.push(element);
+ });
- if (this.count == 5) {
- notifier.subject.unregister(this);
- this.count = 0;
- }
- }));
- req.get();
+ return ret;
+ var text = (new XMLSerializer()).serializeToString(parsed[0])
+ .replace(/<[^>]+>/g, function(all) all.toLowerCase())
+ .replace(/<!--(?:[^-]|-(?!->))*-->/g, ''); // actually
+ return text;
+ },
+ buildMessages: function(diff) {
+ var ret = [];
+ diff.forEach(function(d) {
+ ret.push(
+ new notifier.Message('Hatelab bottle', $U.xmlSerialize(d), {
+ growl: {
+ life: 7000
+ }
+ })
+ );
+ });
+ return ret;
}
});