Catalog npm
PACKAGE EXPLORERView in registry

2ch

npm

A JavaScript library for comfortable 2ch watching.

2ch
Versions collected4
Direct dependencies16From release 0.1.3
Last observed20 Oct, 19:09 UTC

README

Version 0.1.3 documentation

2ch Build Status

A JavaScript library for comfortable 2ch watching.

Getting Started

Install the module with: npm install 2ch --save

var watcher = new require('2ch').ThreadWatcher('iPhone', /パズル&ドラゴンズ/);
watcher.on('update', function(messages) {
  // do something.
});
watcher.start();

Documentation

Constructor arguments

new ThreadWatcher(bbsName, query, interval [, bbsMenu ])

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

The ThreadWatcher class inherited from EventEmitter2. So you can use EventEmitter2 methods basically.

start

Start watching 2ch.

stop

Stop watching 2ch.

isWaching

Return true, when waching is started. Return false, otherwise.

Events

update

The update event is emitted, when the watched thread has new messages. The callback take the messages argument.

watcher.on('update', function(messages) {
  messages.forEach(function(message) {
    console.log(
      message.number,
      message.postedAt.format('YYYY/MM/DD HH:mm:ss'), // moment object.
      message.name,
      message.mail,
      message.tripId,
      message.body
    );
  });
});

error

The error event is emitted, when a error occured in the library. 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.

reload

The reload event is emitted, when the watched thread is reloaded for deleting a message. The callback take the title argument.

begin

The begin event is emitted, when the watched thread is found. The callback take the title argument.

end

The end event is emitted, when the watched thread is ended. The callback take the title argument.

notfound

The notfound event is emitted, when the watched thread is not found by specified query.

Examples

var ThreadWatcher = require('2ch').ThreadWatcher,
    watcher = new ThreadWatcher('番組ch(NHK)', /NHK総合を常に実況し続けるスレ/, 5000),
    loaded = false;

watcher.on('update', function(messages) {
  if (!loaded) {
    loaded = true;
    return;
  }
  messages.forEach(function(message) {
    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, '')
    );
  });
});

watcher.on('error', function(error) {
  console.log(error);
  watcher.stop();
});

watcher.on('reload', function(title) {
  console.log(title, 'のスレッドが再読込されました');
  loaded = false;
});

watcher.on('begin', function(title) {
  console.log(title, 'のスレッドが開始しました');
});

watcher.on('end', function(title) {
  console.log(title, 'のスレッドが終了しました');
});

watcher.start();

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

TODO

  • Browserify

Release History

  • 2013-11-20   v0.1.3   Fix deleted messages bug.
  • 2013-09-14   v0.1.2   Remove cheerio.
  • 2013-06-19   v0.1.1   Modified it.
  • 2013-06-17   v0.1.0   First release.

License

Copyright (c) 2013 Shogo Iwano Licensed under the MIT license.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.3Registry latest20 Nov 201316
0.1.214 Sept 201316
0.1.118 Jun 201317
0.1.016 Jun 201317

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
shiwano/2ch

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:09 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:c6ded1db8bf70a865587fa1f901ecdc49abdaa824146377d44fd26224ea2407b