aboutsummaryrefslogtreecommitdiffstats
path: root/notifier
diff options
context:
space:
mode:
authorsuVene2009-01-09 14:22:16 +0000
committersuVene2009-01-09 14:22:16 +0000
commit0e1e785c0a20896fe23cad14c0b676d70280f51c (patch)
treef6644fe2126712cb7ac7434d542d71ad59dac880 /notifier
parent5e7835783ced42ba4e3a580abef4c09a613eb2d2 (diff)
downloadvimperator-plugins-0e1e785c0a20896fe23cad14c0b676d70280f51c.tar.bz2
* cosmetic changes.
* SubjectHttp#diff return parsed. * subject_weather_yahoo ajust next time. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28211 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'notifier')
-rw-r--r--notifier/subject_weather_yahoo.js159
1 files changed, 80 insertions, 79 deletions
diff --git a/notifier/subject_weather_yahoo.js b/notifier/subject_weather_yahoo.js
index 2868140..72bcaa0 100644
--- a/notifier/subject_weather_yahoo.js
+++ b/notifier/subject_weather_yahoo.js
@@ -1,28 +1,28 @@
/*** BEGIN LICENSE BLOCK {{{
- Copyright (c) 2008 suVene<suvene@zeromemory.info>
+ Copyright (c) 2008 suVene<suvene@zeromemory.info>
- distributable under the terms of an MIT-style license.
- http://www.opensource.jp/licenses/mit-license.html
+ distributable under the terms of an MIT-style license.
+ http://www.opensource.jp/licenses/mit-license.html
}}} END LICENSE BLOCK ***/
// PLUGIN_INFO//{{
var PLUGIN_INFO =
<VimperatorPlugin>
- <name>{NAME}</name>
- <description>Yahoo! Weather forecast notice.</description>
- <description lang="ja">Yahoo!天気予報通知。</description>
- <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
- <version>0.1.2</version>
- <license>MIT</license>
- <minVersion>2.0pre</minVersion>
- <maxVersion>2.0pre</maxVersion>
- <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/subject_weather_yahoo.js</updateURL>
- <detail><![CDATA[
+ <name>{NAME}</name>
+ <description>Yahoo! Weather forecast notice.</description>
+ <description lang="ja">Yahoo!天気予報通知。</description>
+ <author mail="suvene@zeromemory.info" homepage="http://zeromemory.sblo.jp/">suVene</author>
+ <version>0.1.3</version>
+ <license>MIT</license>
+ <minVersion>2.0pre</minVersion>
+ <maxVersion>2.0pre</maxVersion>
+ <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/subject_weather_yahoo.js</updateURL>
+ <detail><![CDATA[
== Options ==
>||
liberator.globalVariables.subject_weather_yahoo_urls = [url1, url2,…]
||<
- @see http://weather.yahoo.co.jp/weather/
- ]]></detail>
+ ]]></detail>
</VimperatorPlugin>;
//}}}
(function() {
@@ -32,84 +32,85 @@ if (!notifier) return;
var libly = notifier.libly;
var $U = libly.$U;
-var logger = $U.getLogger('subject_weather_yahoo');
+var logger = $U.getLogger("subject_weather_yahoo");
var URLs = liberator.globalVariables.subject_weather_yahoo_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'
+ "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 yjw_pinpoint_today yjw_pinpoint_tomorrow")'
- );
- if (!parsed.length) return;
+ 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 yjw_pinpoint_today 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;
+ 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];
- }
+ if (yahooToday == now.getDate()) {
+ source = parsed[1];
+ } else {
+ source = parsed[2];
+ }
- var table = $U.getFirstNodeFromXPath('descendant::table', source);
- table.style.width = '95%';
- table.style.color = '#222';
- var cloneTable = table.cloneNode(false);
- this.cloneTable(cloneTable, table, start, start + 3, true);
+ var table = $U.getFirstNodeFromXPath("descendant::table", source);
+ table.style.width = "95%";
+ table.style.color = "#222";
+ 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);
+ // 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);
- 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)
- new notifier.Message('Weather forecast by Yahoo!', $U.xmlSerialize(diff), url)
- });
+ var next = new Date();
+ next.setHours(now.getHours() + 1)
+ next.setMinutes(0);
+ next.setSeconds(30);
+ this.interval = (next.getTime() - now.getTime()) / 1000;
+
+ 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)
+ new notifier.Message("Weather forecast by Yahoo!", $U.xmlSerialize(diff), url)
+ });
});
})();
-// vim: set fdm=marker sw=4 ts=4 sts=0 et:
+// vim: set fdm=marker sw=2 ts=2 sts=0 et: