From e2878b75a4e7643bc9acbd412b2e95485ec8ddfc Mon Sep 17 00:00:00 2001 From: gigobyte Date: Thu, 17 Nov 2016 23:42:55 +0200 Subject: [PATCH] getActiveThreads done --- src/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/index.js b/src/index.js index 333b28f9..5874bb0f 100644 --- a/src/index.js +++ b/src/index.js @@ -237,6 +237,28 @@ class HLTV extends ParsingTools { return match } + + async getActiveThreads() { + let threads = [] + + const response = await fetch(HLTV_URL).then(res => res.text()) + const $ = cheerio.load(response) + + const $threadNames = $('div[style*="width: 110px"]') + const $threadReplyCount = $('div[style*="width: 30px"]') + + for(let i = 0; i < $threadNames.length; i++) { + const $thread = $($threadNames[i]) + + threads[i] = { + title: this._cleanupString($thread.text()), + link: $thread.find('a').attr('href'), + replies: parseInt($($threadReplyCount[i]).text().slice(1)) + } + } + + return threads + } } export default HLTV