Comparing version 2.0.0 to 2.1.0
@@ -12,5 +12,5 @@ #! /usr/bin/env node | ||
console.log(colour.yellow(' ---------------------')); | ||
console.log(colour.yellow(' A F T O N B L A D E T')); | ||
console.log(colour.yellow(' ---------------------')); | ||
console.log(colour.yellow(' --------------------- ')); | ||
console.log(colour.yellow(' A F T O N B L A D E T ')); | ||
console.log(colour.yellow(' --------------------- ')); | ||
console.log('\n'); | ||
@@ -22,3 +22,3 @@ | ||
* @param {String} text - String to search in | ||
* @return {Number} - Occurances found. | ||
* @return {Number} - Occurrences found. | ||
*/ | ||
@@ -30,2 +30,43 @@ function getJustNuCount (text) { | ||
/** | ||
* Finds multiple "subtitles" in a paragraph and returns them in an array. | ||
* | ||
* @param {String} text - String to search in | ||
* @return {String[]} - Array of topics found. | ||
*/ | ||
function getParagraphParts (text) { | ||
const parts = text.split('<span'); | ||
let subtitles = []; | ||
function containsArrow (str) { | ||
return str.indexOf('abIconArrow') !== -1; | ||
} | ||
function containsCheckmark (str) { | ||
return str.indexOf('abSymbBo') !== -1; | ||
} | ||
for (let part of parts) { | ||
if (containsArrow(part) || containsCheckmark(part)) { | ||
let symbol = part.split('</span>')[0] | ||
, subtitle = part.split('</span>')[1]; | ||
symbol = containsArrow(symbol) ? '➞' : '√'; | ||
if (subtitle.indexOf('</p>') !== -1) { | ||
subtitle = subtitle.split('</p>')[0]; | ||
} | ||
subtitle = subtitle.trim(); | ||
subtitles.push({ | ||
symbol, | ||
subtitle | ||
}); | ||
} | ||
} | ||
return subtitles; | ||
} | ||
/** | ||
* Finds multiple "JUST NU" in a string and returns them in an array. | ||
@@ -36,3 +77,3 @@ * | ||
*/ | ||
function saveTopic (text) { | ||
function getTopics (text) { | ||
const justNus = text.split(/JUST NU:/g); | ||
@@ -43,6 +84,20 @@ let arr = []; | ||
if (justNu.indexOf('</span>') !== -1 && justNu.indexOf('</h2>') !== -1) { | ||
let topic = justNu.split('</span>')[1].split('</h2>')[0]; | ||
let header = justNu.split('</span>')[1].split('</h2>')[0].replace(/\s+/, '') | ||
, paragraphLine | ||
, subtitles | ||
; | ||
if (topic.indexOf('<') === -1) { | ||
arr.push(topic); | ||
if (header && header.indexOf('<') === -1) { | ||
paragraphLine = justNu.split(header)[1].split('</p>')[0]; | ||
if (paragraphLine) { | ||
subtitles = getParagraphParts(paragraphLine); | ||
} | ||
header = header.replace(/\s+/g, ' ').trim(); | ||
arr.push({ | ||
header, | ||
subtitles | ||
}); | ||
} | ||
@@ -67,3 +122,11 @@ } | ||
for (let topic of topics) { | ||
console.log(' ' + colour.red('√') + topic.toUpperCase()); | ||
let header = colour.red('JUST NU: ') + topic.header; | ||
console.log(` ${header}`); | ||
for (let subtitle of topic.subtitles) { | ||
let symbol = colour.red(subtitle.symbol); | ||
console.log(` ${symbol} ${subtitle.subtitle}`); | ||
} | ||
} | ||
@@ -82,3 +145,3 @@ | ||
justNuCount += count; | ||
justNuTopics = justNuTopics.concat(saveTopic(chunk)); | ||
justNuTopics = justNuTopics.concat(getTopics(chunk)); | ||
} | ||
@@ -85,0 +148,0 @@ }); |
{ | ||
"name": "just-nu", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Antal JUST NU på Aftonbladet", | ||
@@ -31,3 +31,6 @@ "main": "index.js", | ||
"colour": "^0.7.1" | ||
}, | ||
"engines": { | ||
"node": ">=6.0.0" | ||
} | ||
} |
@@ -0,3 +1,7 @@ | ||
# just-nu [![Build Status](https://travis-ci.org/enjikaka/just-nu.svg?branch=master)](https://travis-ci.org/enjikaka/just-nu) | ||
Install this globally and run `just-nu` to know how many "JUST NU" there is on Aftonbladet right now. | ||
![](http://image.prntscr.com/image/b8a213c167694e72ac4ebeb996633c9c.png) | ||
Made with laughs in the forests of western Sweden. |
5343
7
112
8