Comparing version 0.1.0 to 0.1.1
(function() { | ||
var BbsMenu, EventEmitter2, cheerio, moment, util, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
var BbsMenu, cheerio, moment, util; | ||
@@ -10,9 +8,5 @@ cheerio = require('cheerio'); | ||
EventEmitter2 = require('eventemitter2').EventEmitter2; | ||
util = require('./util'); | ||
module.exports = BbsMenu = (function(_super) { | ||
__extends(BbsMenu, _super); | ||
module.exports = BbsMenu = (function() { | ||
function BbsMenu() { | ||
@@ -29,3 +23,2 @@ this.menuUrl = 'http://menu.2ch.net/bbsmenu.html'; | ||
if (error) { | ||
_this.emit('error', error); | ||
return done(error); | ||
@@ -47,3 +40,2 @@ } | ||
_this.updatedAt = moment(); | ||
_this.emit('update'); | ||
return typeof done === "function" ? done() : void 0; | ||
@@ -63,4 +55,4 @@ }); | ||
})(EventEmitter2); | ||
})(); | ||
}).call(this); |
(function() { | ||
var Bbs, BbsMenu, EventEmitter, Thread, ThreadWatcher, _, | ||
var Bbs, BbsMenu, BbsMenuFactory, EventEmitter, Thread, ThreadWatcher, bbsMenuFactory, _, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -17,12 +17,29 @@ __hasProp = {}.hasOwnProperty, | ||
BbsMenuFactory = (function() { | ||
function BbsMenuFactory() {} | ||
BbsMenuFactory._bbsMenu = null; | ||
BbsMenuFactory.prototype.get = function() { | ||
if (!this._bbsMenu) { | ||
this._bbsMenu = new BbsMenu(); | ||
} | ||
return this._bbsMenu; | ||
}; | ||
return BbsMenuFactory; | ||
})(); | ||
bbsMenuFactory = new BbsMenuFactory(); | ||
module.exports = ThreadWatcher = (function(_super) { | ||
__extends(ThreadWatcher, _super); | ||
function ThreadWatcher(args) { | ||
function ThreadWatcher(bbsName, query, interval, bbsMenu) { | ||
this.bbsName = bbsName; | ||
this.query = query; | ||
this.interval = interval != null ? interval : 600000; | ||
this.bbsMenu = bbsMenu; | ||
this._run = __bind(this._run, this); | ||
args = _.defaults(args, { | ||
interval: 600000, | ||
bbsMenu: null | ||
}); | ||
this.bbsName = args.bbsName, this.query = args.query, this.interval = args.interval, this.bbsMenu = args.bbsMenu; | ||
if (this.interval < 5000) { | ||
@@ -32,3 +49,3 @@ this.interval = 5000; | ||
if (this.bbsMenu == null) { | ||
this.bbsMenu = new BbsMenu(); | ||
this.bbsMenu = bbsMenuFactory.get(); | ||
} | ||
@@ -44,5 +61,2 @@ this.bbs = new Bbs(this.bbsMenu, this.bbsName); | ||
this.events = { | ||
'bbsMenu error': function(error) { | ||
return _this.emit('error', error); | ||
}, | ||
'thread error': function(error) { | ||
@@ -67,7 +81,2 @@ return _this.emit('error', error); | ||
ThreadWatcher.prototype.destroy = function() { | ||
this._watching = false; | ||
return this.undelegateEvents(); | ||
}; | ||
ThreadWatcher.prototype.delegateEvents = function() { | ||
@@ -152,3 +161,3 @@ var _this = this; | ||
} else if (!header) { | ||
_this.emit('miss'); | ||
_this.emit('notfound'); | ||
return done(null, null); | ||
@@ -155,0 +164,0 @@ } |
(function() { | ||
var Bbs, EventEmitter2, Message, Thread, util, _, | ||
var EventEmitter2, Message, Thread, util, _, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -12,4 +12,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
Bbs = require('./bbs'); | ||
Message = require('./message'); | ||
@@ -16,0 +14,0 @@ |
{ | ||
"name": "2ch", | ||
"description": "A JavaScript library for comfortable 2ch watching.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/shiwano/2ch", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -8,6 +8,3 @@ # 2ch | ||
```javascript | ||
var watcher = new require('2ch').ThreadWatcher({ | ||
bbsName: 'iPhone', | ||
query: /パズル&ドラゴンズ/, | ||
}); | ||
var watcher = new require('2ch').ThreadWatcher('iPhone', /パズル&ドラゴンズ/); | ||
watcher.on('update', function(messages) { | ||
@@ -20,2 +17,25 @@ // do something. | ||
## Documentation | ||
### Constructor arguments | ||
#### bbsName | ||
A string which is a valid board name in 2ch. | ||
#### query | ||
A string or RegExp which is used to find the watched thread. | ||
#### interval (default: 600000) | ||
A number determining the update interval. It is at least 5000. | ||
#### bbsMenu (default: null) | ||
A BbsMenu instance object. In most cases, there is no need to specify. | ||
### Methods | ||
#### start | ||
Start watching 2ch. | ||
#### stop | ||
Stop watching 2ch. | ||
#### isWaching | ||
Return `true`, when waching is started. Return `false`, otherwise. | ||
### Events | ||
@@ -44,3 +64,2 @@ #### update | ||
The callback take the `error` argument. | ||
If there is no listener for it, then the default action is to print a stack trace and exit the program. | ||
@@ -60,20 +79,24 @@ | ||
#### notfound | ||
The `notfound` event is emitted, when the watched thread is not found by specified query. | ||
## Examples | ||
```javascript | ||
var _2ch = require('2ch'), | ||
ThreadWatcher = _2ch.ThreadWatcher, | ||
BbsMenu = _2ch.BbsMenu; | ||
var ThreadWatcher = require('../../lib/2ch').ThreadWatcher, | ||
watcher = new ThreadWatcher('番組ch(NHK)', /NHK総合を常に実況し続けるスレ/, 5000), | ||
loaded = false; | ||
var bbsMenu = new BbsMenu(); // common object | ||
var watcher = new ThreadWatcher({ | ||
bbsName: '番組ch(NHK)', | ||
query: /NHK総合を常に実況し続けるスレ/, | ||
interval: 60000, // at least 5000 | ||
bbsMenu: bbsMenu | ||
}); | ||
watcher.on('update', function(messages) { | ||
if (!loaded) { | ||
loaded = true; | ||
return; | ||
} | ||
messages.forEach(function(message) { | ||
console.log(message.number, message.rawString); | ||
console.log( | ||
message.number, | ||
message.name.replace(/<[^<>]+>/g, ''), | ||
message.postedAt.format('YYYY/MM/DD HH:mm:ss'), // moment object. | ||
message.tripId, | ||
message.body.replace(/<[^<>]+>/g, '') | ||
); | ||
}); | ||
@@ -84,6 +107,12 @@ }); | ||
console.log(error); | ||
watcher.stop(); | ||
}); | ||
watcher.on('reload', function(title) { | ||
console.log(title, 'のスレッドが再読込されました'); | ||
loaded = false; | ||
}); | ||
watcher.on('begin', function(title) { | ||
console.log(title, 'のスレッドが立てられました'); | ||
console.log(title, 'のスレッドが開始しました'); | ||
}); | ||
@@ -105,2 +134,3 @@ | ||
## Release History | ||
* 2013-06-19 v0.1.1 Modified it. | ||
* 2013-06-17 v0.1.0 First release. | ||
@@ -107,0 +137,0 @@ |
@@ -1,17 +0,18 @@ | ||
var _2ch = require('../../lib/2ch'), | ||
ThreadWatcher = _2ch.ThreadWatcher, | ||
BbsMenu = _2ch.BbsMenu; | ||
var ThreadWatcher = require('../../lib/2ch').ThreadWatcher, | ||
watcher = new ThreadWatcher('番組ch(NHK)', /NHK総合を常に実況し続けるスレ/, 5000), | ||
loaded = false; | ||
var bbsMenu = new BbsMenu(); // common object | ||
var watcher = new ThreadWatcher({ | ||
bbsName: '番組ch(NHK)', | ||
query: /NHK総合を常に実況し続けるスレ/, | ||
interval: 5000, // at least 5000 | ||
bbsMenu: bbsMenu | ||
}); | ||
watcher.on('update', function(messages) { | ||
if (!loaded) { | ||
loaded = true; | ||
return; | ||
} | ||
messages.forEach(function(message) { | ||
console.log(message.number, message.rawString); | ||
console.log( | ||
message.number, | ||
message.name.replace(/<[^<>]+>/g, ''), | ||
message.postedAt.format('YYYY/MM/DD HH:mm:ss'), // moment object. | ||
message.tripId, | ||
message.body.replace(/<[^<>]+>/g, '') | ||
); | ||
}); | ||
@@ -22,6 +23,12 @@ }); | ||
console.log(error); | ||
watcher.stop(); | ||
}); | ||
watcher.on('reload', function(title) { | ||
console.log(title, 'のスレッドが再読込されました'); | ||
loaded = false; | ||
}); | ||
watcher.on('begin', function(title) { | ||
console.log(title, 'のスレッドが立てられました'); | ||
console.log(title, 'のスレッドが開始しました'); | ||
}); | ||
@@ -28,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140118
33
506
135