UNPKG

2ch

Version:

A JavaScript library for comfortable 2ch watching.

54 lines (43 loc) 1.41 kB
(function() { var BbsMenu, moment, util; moment = require('moment'); util = require('./util'); module.exports = BbsMenu = (function() { BbsMenu.prototype.reStrAtag = '<A HREF=(http:\\/\\/[^/]+(2ch.net|bbspink.com)\\/[^/]+\\/)>([^<>]+)<\\/A>'; function BbsMenu() { this.menuUrl = 'http://menu.2ch.net/bbsmenu.html'; this.updatedAt = null; this._bbsUrls = {}; } BbsMenu.prototype.update = function(done) { var _this = this; return this.fetch(function(error, res) { var atags, reAtag; if (error) { return done(error); } atags = res.body.text.match(new RegExp(_this.reStrAtag, 'ig')); reAtag = new RegExp(_this.reStrAtag, 'i'); atags.forEach(function(atag) { var matches, name, url; matches = atag.match(reAtag); url = matches[1]; name = matches[3]; if (name === '2ch総合案内') { return; } return _this._bbsUrls[name] = url; }); _this.updatedAt = moment(); return typeof done === "function" ? done() : void 0; }); }; BbsMenu.prototype.fetch = function(done) { return util.requestGet(this.menuUrl).end(done); }; BbsMenu.prototype.getBbsUrl = function(bbsName) { return this._bbsUrls[bbsName] || null; }; return BbsMenu; })(); }).call(this);