From 8860ec5b9f362284b66a2abbefe7071bf756c768 Mon Sep 17 00:00:00 2001 From: suVene Date: Mon, 15 Dec 2008 16:51:03 +0000 Subject: * growl.css - add head link style. * observer_growl.js - add hyperlink.mod default life 10 seconds. * subject_hatelabo_bottle.js - parse permalink. * notifier.js - follow pluginManager.etc. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26822 d0d07461-0603-4401-acd4-de1884942a52 --- notifier.js | 135 +++++++++++++++++++----------------- notifier/growl.css | 11 ++- notifier/observer_growl.js | 21 ++++-- notifier/subject_hatelabo_bottle.js | 21 +++--- 4 files changed, 104 insertions(+), 84 deletions(-) diff --git a/notifier.js b/notifier.js index 2b084ba..6bc6277 100644 --- a/notifier.js +++ b/notifier.js @@ -1,110 +1,113 @@ // PLUGIN_INFO//{{{ var PLUGIN_INFO = - {name} + {NAME} notice of change framework. 変更通知フレームワーク。 suVene - 0.1.1 + 0.1.2 2.0pre 2.0pre ; //}}} @@ -167,12 +170,13 @@ function bootstrap() { this.initialize.apply(this, arguments); }; Message.prototype = { - initialize: function(title, message, options) { + initialize: function(title, message, link, options) { try { if (typeof title == 'undefined' || title == null) throw 'title is undefined.'; if (typeof message == 'undefined' || message == null) throw 'message is undefined.'; this.title = title; this.message = message; + this.link = link; this.options = options; } catch (e) { logger.log('Message.initialize error: ' + e); @@ -232,7 +236,7 @@ function bootstrap() { var req = new libly.Request( this.options.url, this.options.headers, - this.options.extra + $U.extend({ asynchronous: true }, this.options.extra) ); req.addEventListener('onSuccess', $U.bind(this, function(res) { logger.log('initialized'); @@ -249,7 +253,7 @@ function bootstrap() { var req = new libly.Request( this.options.url, this.options.headers, - this.options.extra + $U.extend({ asynchronous: false }, this.options.extra) ); req.addEventListener('onSuccess', $U.bind(this, function(res) { var parsed, diff; @@ -258,7 +262,7 @@ function bootstrap() { if (diff && (typeof diff.length != 'undefined' && diff.length > 0)) { this.cache = parsed; if (typeof this.buildMessages == 'function') { - let messages = this.buildMessages([].concat(diff)); + let messages = this.buildMessages(diff); [].concat(messages).forEach($U.bind(this, function(m) { this.notify(m); liberator.sleep(1500); @@ -267,7 +271,8 @@ function bootstrap() { } })); req.get(); - } + }, + diff: function(cache, parsed) cache });//}}} var Notifier = function() {//{{{ @@ -337,11 +342,11 @@ function bootstrap() { liberator.dump('window:' + window.content.window); this.subjects.getPlugins().forEach(function(s) { let now = new Date(); - if (!s.__nextTime) s.nexttime = now; + if (!s.__nextTime) s.__nextTime = now; if (s.interval > 0 && !s.isActive && s.__nextTime <= now) { + s.isActive = true; setTimeout(function() { let start = (new Date()).getTime(); - s.isActive = true; if (typeof s.check == 'function') try { s.check(); } catch (e) { logger.log('subject.check error: ' + e) } let stop = (new Date()).getTime(); diff --git a/notifier/growl.css b/notifier/growl.css index 5cbd9ed..0912af4 100644 --- a/notifier/growl.css +++ b/notifier/growl.css @@ -45,8 +45,6 @@ div.observer_growl div.observer_growl_notification, div.observer_growl div.obser background-color: #000; color: #fff; opacity: .85; - filter: alpha(opacity = 85); - zoom: 1; width: 235px; padding: 10px; margin-top: 5px; @@ -56,7 +54,6 @@ div.observer_growl div.observer_growl_notification, div.observer_growl div.obser text-align: left; display: none; -moz-border-radius: 5px; - -webkit-border-radius: 5px; } div.observer_growl div.observer_growl_notification { @@ -68,6 +65,14 @@ div.observer_growl div.observer_growl_notification div.header { font-size: 10px; } +div.observer_growl div.observer_growl_notification div.header a:link { + color: #EF6D29; +} + +div.observer_growl div.observer_growl_notification div.header a:hover { + color: #A50000; +} + div.observer_growl div.observer_growl_notification div.close { float: right; font-weight: bold; diff --git a/notifier/observer_growl.js b/notifier/observer_growl.js index 8f973c6..9fb8f88 100644 --- a/notifier/observer_growl.js +++ b/notifier/observer_growl.js @@ -1,11 +1,11 @@ // PLUGIN_INFO//{{{ var PLUGIN_INFO = - {name} + {NAME} notification from the subjects is notified to you by the Growl style. Growl風通知。 suVene - 0.1.0 + 0.1.1 2.0pre 2.0pre ; @@ -24,7 +24,7 @@ var Growl = function() {//{{{ }; Growl.prototype = { defaults: { - life: 5000 + life: 10000 }, initialize: function(dom, container, options) { this.dom = dom; @@ -62,12 +62,13 @@ notifier.observer.register(notifier.Observer, { var doc = window.content.document; var container = doc.getElementById("observer_growl"); if (!container) { - doc.body.appendChild(util.xmlToDom(
, doc)); + doc.body.appendChild($U.xmlToDom(
, doc)); container = doc.getElementById("observer_growl"); } var notification = this.createPopup(message, doc, container); // TODO: animation!!! + var node = doc.importNode(notification, true); container.appendChild(notification); if (container.childNodes.length == 1) { @@ -82,11 +83,17 @@ notifier.observer.register(notifier.Observer, { var html =
×
-
{new XMLList(this.count + ': ' + message.title)}
+
{new XMLList( + (message.link ? '' : '') + + this.count + ': ' + message.title + + (message.link ? '' : '') + )}
{new XMLList(message.message || '')}
; - dom = util.xmlToDom(html, doc, nodes); - dom.__data__ = new Growl(dom, nodes, message.options.growl); + dom = $U.xmlToDom(html, doc, nodes); + // TODO: get settings + var options = {}; + dom.__data__ = new Growl(dom, nodes, {}); return dom; }, checkStatus: function() { diff --git a/notifier/subject_hatelabo_bottle.js b/notifier/subject_hatelabo_bottle.js index 2335cad..71a5a27 100644 --- a/notifier/subject_hatelabo_bottle.js +++ b/notifier/subject_hatelabo_bottle.js @@ -1,7 +1,7 @@ // PLUGIN_INFO//{{{ var PLUGIN_INFO = - {name} + {NAME} notifies if hatena bottle was changed. はてなボトルの変更通知。 suVene @@ -32,18 +32,21 @@ notifier.subject.register(notifier.SubjectHttp, { logger.log('preInitialize: '); }, parse: function(res) { - // if (this.count == 0) return []; for debug - if (!res.isSuccess() || res.responseText == '') return null; - return res.getHTMLDocument('id("body")//div[contains(concat(" ", @class, " "), " entry ")]'); + // if (this.count == 0) return []; // for debug + var doc = res.getHTMLDocument('id("body")//div[contains(concat(" ", @class, " "), " entry ")]'); + return doc; }, diff: function(cache, parsed) parsed.filter(function(element) !cache.some(function(c) c.textContent == element.textContent)), - buildMessages: function(diff) - diff.map(function(d) - new notifier.Message('Hatelab bottle', $U.xmlSerialize(d), { - growl: { life: 7000 } - })) + buildMessages: function(diff) { + return diff.map($U.bind(this, function(d) { + var permalink = $U.getNodesFromXPath('descendant::a[@class="hatena-star-uri"]', d); + if (permalink.length > 0) + permalink = URL + permalink[0]; + return new notifier.Message('Hatelab bottle', $U.xmlSerialize(d), permalink) + })); + } }); })(); -- cgit v1.2.3