diff options
| -rw-r--r-- | notifier.js | 14 | ||||
| -rw-r--r-- | notifier/growl.css | 4 | ||||
| -rw-r--r-- | notifier/observer_growl.js | 65 | ||||
| -rw-r--r-- | notifier/subject_hatelabo_bottle.js | 4 | ||||
| -rwxr-xr-x | notifier/subject_weather_yahoo.js | 101 | 
5 files changed, 163 insertions, 25 deletions
diff --git a/notifier.js b/notifier.js index 1ea68af..459189d 100644 --- a/notifier.js +++ b/notifier.js @@ -2,14 +2,14 @@  var PLUGIN_INFO =  <VimperatorPlugin>      <name>{NAME}</name> -    <description>notice of change framework.</description> +    <description>change notice framework.</description>      <description lang="ja">変更通知フレームワーク。</description>      <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>      <version>0.1.2</version>      <minVersion>2.0pre</minVersion>      <maxVersion>2.0pre</maxVersion>      <detail><![CDATA[ -== NEEDS LIBRARY == +== Needs Library ==  - _libly.js(ver.0.1.9)    @see http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/_libly.js @@ -108,7 +108,7 @@ buildMessages(diff):      必ず実装して下さい。      this.diff() により抽出されたオブジェクトを元に、liberator.plugins.notifier.Message のインスタンス、      または、その配列を返却して下さい。 -  ]]></detail> +    ]]></detail>  </VimperatorPlugin>;  //}}}  (function() { @@ -259,14 +259,16 @@ function bootstrap() {                  var parsed, diff;                  if (typeof this.parse == 'function') parsed = this.parse(res);                  if (parsed && typeof this.diff == 'function') diff = this.diff(this.cache, parsed); -                if (diff && (typeof diff.length != 'undefined' && diff.length > 0)) { +                if (diff && +                    (typeof diff.length == 'undefined' || +                    (typeof diff.length != 'undefined' && diff.length > 0))) {                      this.cache = parsed;                      if (typeof this.buildMessages == 'function') {                          let messages = this.buildMessages(diff); -                        [].concat(messages).forEach($U.bind(this, function(m) { +                        [].concat(messages).forEach(function(m) {                              this.notify(m);                              liberator.sleep(1500); -                        })); +                        }, this);                      }                  }              })); diff --git a/notifier/growl.css b/notifier/growl.css index 0912af4..d67b681 100644 --- a/notifier/growl.css +++ b/notifier/growl.css @@ -65,11 +65,11 @@ div.observer_growl div.observer_growl_notification div.header {      font-size: 10px;  } -div.observer_growl div.observer_growl_notification div.header a:link { +div.observer_growl div.observer_growl_notification a:link {      color: #EF6D29;  } -div.observer_growl div.observer_growl_notification div.header a:hover { +div.observer_growl div.observer_growl_notification a:visited {      color: #A50000;  } diff --git a/notifier/observer_growl.js b/notifier/observer_growl.js index 9fb8f88..f26c850 100644 --- a/notifier/observer_growl.js +++ b/notifier/observer_growl.js @@ -8,6 +8,37 @@ var PLUGIN_INFO =      <version>0.1.1</version>      <minVersion>2.0pre</minVersion>      <maxVersion>2.0pre</maxVersion> +    <detail><![CDATA[ +== Settings == +>|| +liberator.globalVariables.observer_growl_settings = { +    'message title': { +        life: number,           // sec (10 sec by default) +        sticky: bool,           // true or false (false by default) +        sticky_keyword: [       // keyword ary +            'keyword1', +            'keyword2' +        ], +        hide: bool              // true or false (false by default) +                                //   however it's displayed when there is a keyword in the message. +    } +}; +||< +e.g.) +>|| +javascript <<EOM +liberator.globalVariables.observer_growl_settings = { +    'Hatelabo bottle': { life: 20, keyword: 'はてな' }, +    'Weather forecast by Yahoo!': { sticky: true } +}; +EOM +||< + +== Todo == +- sticky_keyword +- hide +- close all +    ]]></detail>  </VimperatorPlugin>;  //}}}  (function() { @@ -24,19 +55,21 @@ var Growl = function() {//{{{  };  Growl.prototype = {      defaults: { -        life: 10000 +        life: 10, +        sticky: false, +        suticky_keyword: [], +        hide: false,      }, -    initialize: function(dom, container, options) { -        this.dom = dom; +    initialize: function(node, container, options) { +        this.node = node;          this.container = container;          this.created = new Date();          this.options = $U.extend(this.defaults, (options || {})); -        this.life = this.options.life; -        dom.childNodes[0].addEventListener("click", $U.bind(this, this.remove), false); +        node.childNodes[0].addEventListener("click", $U.bind(this, this.remove), false);      },      remove: function() {          // TODO: animation!!!! -        this.container.removeChild(this.dom); +        this.container.removeChild(this.node);      },  };//}}} @@ -44,6 +77,7 @@ Growl.prototype = {  notifier.observer.register(notifier.Observer, {      initialize: function () {          this.count = 1; +        this.settings;          io.getRuntimeDirectories('').forEach(function(dir) {              var path = io.expandPath(dir.path + '/plugin/notifier'); @@ -56,6 +90,8 @@ notifier.observer.register(notifier.Observer, {                  }              });          }); + +        this.settings = liberator.globalVariables.observer_growl_settings || {};      },      update: function(message) { @@ -68,7 +104,7 @@ notifier.observer.register(notifier.Observer, {          var notification = this.createPopup(message, doc, container);          // TODO: animation!!! -        var node = doc.importNode(notification, true); +        //container.appendChild(doc.importNode(notification, true));          container.appendChild(notification);          if (container.childNodes.length == 1) { @@ -78,8 +114,8 @@ notifier.observer.register(notifier.Observer, {          this.count++;      }, -    createPopup: function(message, doc, nodes) { -        var dom; +    createPopup: function(message, doc, container) { +        var node;          var html =              <div class="observer_growl_notification" style="display: block;">                  <div class="close">×</div> @@ -90,11 +126,9 @@ notifier.observer.register(notifier.Observer, {                      )}</div>                  <div class="message">{new XMLList(message.message || '')}</div>              </div>; -        dom = $U.xmlToDom(html, doc, nodes); -        // TODO: get settings -        var options = {}; -        dom.__data__ = new Growl(dom, nodes, {}); -        return dom; +        node = $U.xmlToDom(html, doc); +        node.__data__ = new Growl(node, container, this.settings[message.title]); +        return node;      },      checkStatus: function() { @@ -107,7 +141,8 @@ notifier.observer.register(notifier.Observer, {              let item = container.childNodes[i];              let growl = item.__data__;              if (growl && growl.created && -                growl.created.getTime() + growl.life < (new Date()).getTime()) { +                !growl.options.sticky && +                growl.created.getTime() + (growl.options.life * 1000) < (new Date()).getTime()) {                  removeNodes.push(item);              }          } diff --git a/notifier/subject_hatelabo_bottle.js b/notifier/subject_hatelabo_bottle.js index 71a5a27..a21f22f 100644 --- a/notifier/subject_hatelabo_bottle.js +++ b/notifier/subject_hatelabo_bottle.js @@ -2,7 +2,7 @@  var PLUGIN_INFO =  <VimperatorPlugin>      <name>{NAME}</name> -    <description>notifies if hatena bottle was changed.</description> +    <description>hatena bottle change notice.</description>      <description lang="ja">はてなボトルの変更通知。</description>      <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>      <version>0.1.1</version> @@ -44,7 +44,7 @@ notifier.subject.register(notifier.SubjectHttp, {              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) +            return new notifier.Message('Hatelabo bottle', $U.xmlSerialize(d), permalink)          }));      }  }); diff --git a/notifier/subject_weather_yahoo.js b/notifier/subject_weather_yahoo.js new file mode 100755 index 0000000..96f23d0 --- /dev/null +++ b/notifier/subject_weather_yahoo.js @@ -0,0 +1,101 @@ +// PLUGIN_INFO//{{ +var PLUGIN_INFO = +<VimperatorPlugin> +    <name>{NAME}</name> +    <description>yahoo weather forecast notice.</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> +</VimperatorPlugin>; +//}}} +(function() { + +var notifier = liberator.plugins.notifier; +if (!notifier) return; + +var libly = notifier.libly; +var $U = libly.$U; +var logger = $U.getLogger('subject_weather_yahoo'); + +// @see http://weather.yahoo.co.jp/weather/ +var URLs = [ +    'http://weather.yahoo.co.jp/weather/jp/27/6200/27127/5300001.html', +    'http://weather.yahoo.co.jp/weather/jp/13/4410/13113/1500001.html' +]; + +URLs.forEach(function(url) { +    notifier.subject.register(notifier.SubjectHttp, { +        interval: 10, +        options: { +            url: url, +            headers: null, +            extra: { encoding: 'euc-jp' } +        }, +        parse: function(res) { +            var parsed = res.getHTMLDocument( +                            'id("cat-pass") | id("yjw_pinpoint_today") | id("yjw_pinpoint_tomorrow")' +                         ); +            if (!parsed.length) return; + +            var now = new Date(); +            var hours = now.getHours(); +            var start = Math.floor(hours / 3) + 1; +            var yahooToday = $U.getFirstNodeFromXPath('descendant::h3/span/text()', parsed[1]); +            yahooToday = yahooToday.textContent.replace(/.*\u6708(\d+)\u65E5.*/, '$1'); // 月($1)日 +            var source, cloneTable; + + +            if (yahooToday == now.getDate()) { +                source = parsed[1]; +            } else { +                source = parsed[2]; +            } + +            var table = $U.getFirstNodeFromXPath('descendant::table', source); +            table.style.width = '95%'; +            var cloneTable = table.cloneNode(false); +            this.cloneTable(cloneTable, table, start, start + 3, true); + +            // concat tommorow +            if (start > 6) +                this.cloneTable(cloneTable, +                        $U.getFirstNodeFromXPath('descendant::table', parsed[2]), +                        1, (3 - (8 - start)), false); + +            var next = new Date(); +            next.setHours(now.getHours() + 1) +            next.setMinutes(0); +            next.setSeconds(0); +            this.interval = (next.getTime() - now.getTime()) / 1000; + +            var df = window.content.document.createDocumentFragment(); +            df.appendChild(parsed[0]); +            df.appendChild(cloneTable); +            return df; +        }, +        cloneTable: function(source, table, start, end, withHead) { +            var rows = table.getElementsByTagName('tr'); +            for (let r = 0, len = rows.length; r < len; r++) { +                let row = withHead ? rows[r].cloneNode(false) : source.getElementsByTagName('tr')[r]; +                let cols = rows[r].getElementsByTagName('td'); +                if (withHead) +                    source.appendChild(row); +                for (let c = 0, len2 = cols.length; c < len2; c++) { +                    if ((withHead && c == 0) || (start <= c && c < end)) { +                        row.appendChild(cols[c].cloneNode(true)); +                    } +                } +            } +            return source; +        }, +        buildMessages: function(diff) { +            return new notifier.Message('Weather forecast by Yahoo!', $U.xmlSerialize(diff), url); +        } +    }); +}); + +})(); +// vim: set fdm=marker sw=4 ts=4 sts=0 et: +  | 
