diff options
-rw-r--r-- | libly.js | 16 | ||||
-rw-r--r-- | multi_requester.js | 8 | ||||
-rw-r--r-- | notifier.js | 7 | ||||
-rw-r--r-- | notifier/observer_growl.js | 4 | ||||
-rw-r--r-- | notifier/subject_hatelabo_bottle.js | 77 | ||||
-rw-r--r-- | notifier/subject_test.js | 52 |
6 files changed, 94 insertions, 70 deletions
@@ -4,10 +4,10 @@ * @description suvene's library * @description-ja 適当なライブラリっぽいものたち * @author suVene suvene@zeromemory.info - * @version 0.1.0 + * @version 0.1.1 * @minVersion 1.2 * @maxVersion 2.0pre - * Last Change: 07-Dec-2008. + * Last Change: 08-Dec-2008. * ==/VimperatorPlugin== * * HEAD COMMENT {{{ @@ -246,7 +246,7 @@ lib.Response.prototype = { initialize: function(req) { this.req = req; this.transport = req.transport; - this.isSuccess = req.isSuccess(); + this.isSuccess = req.isSuccess; this.readyState = this.transport.readyState; if (this.readyState == 4) { @@ -266,14 +266,14 @@ lib.Response.prototype = { return this.transport.statusText || ''; } catch (e) { return ''; } }, - getHTMLDocument: function(xpath, xmlns) { + getHTMLDocument: function(xpath, xmlns, ignoreTags) { if (!this.doc) { this.htmlFragmentstr = this.responseText.replace(/^[\s\S]*?<html(?:[ \t\n\r][^>]*)?>|<\/html[ \t\r\n]*>[\S\s]*$/ig, '').replace(/[\r\n]+/g, ' '); - let ignoreTags = ['script']; - if (this.req.options.siteinfo.ignoreTags) { - ignoreTags.concat(this.req.options.siteinfo.ignoreTags.split(',')); + var iTags = ['script']; + if (ignoreTags) { + iTags.concat(ignoreTags.split(',')); } - this.htmlStripScriptFragmentstr = lib.$U.stripTags(this.htmlFragmentstr, 'script'); + this.htmlStripScriptFragmentstr = lib.$U.stripTags(this.htmlFragmentstr, iTags); this.doc = this._createHTMLDocument(this.htmlStripScriptFragmentstr, xmlns); } diff --git a/multi_requester.js b/multi_requester.js index 4a9b00d..0f3833f 100644 --- a/multi_requester.js +++ b/multi_requester.js @@ -4,10 +4,10 @@ * @description request, and the result is displayed to the buffer. * @description-ja リクエストの結果をバッファに出力する。 * @author suVene suvene@zeromemory.info - * @version 0.4.2 + * @version 0.4.3 * @minVersion 2.0pre * @maxVersion 2.0pre - * Last Change: 07-Dec-2008. + * Last Change: 08-Dec-2008. * ==/VimperatorPlugin== * * HEAD COMMENT {{{ @@ -365,7 +365,7 @@ var MultiRequester = { try { - if (!res.isSuccess || res.responseText == '') throw 'response is fail or null'; + if (!res.isSuccess() || res.responseText == '') throw 'response is fail or null'; url = res.req.url; escapedUrl = util.escapeHTML(url); @@ -377,7 +377,7 @@ var MultiRequester = { return; } - doc = res.getHTMLDocument(xpath); + doc = res.getHTMLDocument(xpath, null, res.req.options.siteinfo.ignoreTags); if (!doc) throw 'XPath result is undefined or null.: XPath -> ' + xpath; html = '<a href="' + escapedUrl + '" class="hl-Title" target="_self">' + escapedUrl + '</a>' + diff --git a/notifier.js b/notifier.js index db0af9b..126c523 100644 --- a/notifier.js +++ b/notifier.js @@ -29,8 +29,8 @@ if (liberator.plugins.notifier && liberator.plugins.notifier._self) { function bootstrap() { - var lib = liberator.plugins.libly; - var $U = lib.$U; + var libly = liberator.plugins.libly; + var $U = libly.$U; var logger = $U.getLogger('notifier'); var Loader = function() {//{{{ @@ -160,7 +160,7 @@ function bootstrap() { $U.bind(this, function(args) { this.stop() }), null, true ); - liberator.plugins.notifier.lib = lib; + liberator.plugins.notifier.libly = libly; liberator.plugins.notifier.Message = Message; this.observers = new Loader('observer', function(args) new Observer(args)); @@ -213,7 +213,6 @@ function bootstrap() { logger.echo('notifier[' + this.id + '] stopped.(' + start + ')', commandline.force_singleline); }), 10); - logger.log('start end'); },//}}} stop: function(finallycallback) {//{{{ if (!this.timer) { diff --git a/notifier/observer_growl.js b/notifier/observer_growl.js index 2875909..166e1ab 100644 --- a/notifier/observer_growl.js +++ b/notifier/observer_growl.js @@ -17,8 +17,8 @@ var notifier = liberator.plugins.notifier; if (!notifier) return; -var lib = notifier.lib; -var $U = lib.$U; +var libly = notifier.libly; +var $U = libly.$U; var logger = $U.getLogger('observer_growl'); var Growl = function() {//{{{ 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: + diff --git a/notifier/subject_test.js b/notifier/subject_test.js deleted file mode 100644 index b5689c6..0000000 --- a/notifier/subject_test.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * notifier.js plugin subject - * @name subject_test.js - * @description notify if ... - * @description-ja ... の時ポップアップ通知。 - * @author suVene suvene@zeromemory.info - * @version 0.1.0 - * Last Change: 07-Dec-2008. - */ -(function() { - -var notifier = liberator.plugins.notifier; -if (!notifier) return; - -var lib = notifier.lib; -var $U = lib.$U; -var logger = $U.getLogger('subject_test'); - -notifier.subject.register({ - interval: 3, - initialize: function() { - logger.log('initialize'); - this.count = 0; - }, - check: function() { - this.count++; - logger.log('check'); - var req = new lib.Request( - 'http://localhost:8080/index.html', - null, // headers {} - { - encode: 'shift_jis' - } - ); - 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: - |