diff options
Diffstat (limited to 'notifier/subject_hatelabo_bottle.js')
-rw-r--r-- | notifier/subject_hatelabo_bottle.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/notifier/subject_hatelabo_bottle.js b/notifier/subject_hatelabo_bottle.js new file mode 100644 index 0000000..9c4914d --- /dev/null +++ b/notifier/subject_hatelabo_bottle.js @@ -0,0 +1,77 @@ +/** + * 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. + */ +(function() { + +var notifier = liberator.plugins.notifier; +if (!notifier) return; + +var libly = notifier.libly; +var $U = libly.$U; +var logger = $U.getLogger('subject_hatelabo_bottle'); + +var URL = 'http://bottle.hatelabo.jp'; + +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(); + }, + parse: function(res) { + + var ret, dom; + + if (!res.isSuccess() || res.responseText == '') return ret; + + dom = res.getHTMLDocument('id("body")//div[contains(concat(" ", @class, " "), " entry ")]'); + if (!dom) return ret; + + ret = []; + 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); + + if (this.count == 5) { + notifier.subject.unregister(this); + this.count = 0; + } + })); + req.get(); + } +}); + +})(); +// vim: set fdm=marker sw=4 ts=4 sts=0 et: + |