Skip to content

Instantly share code, notes, and snippets.

@majirosstefan
Forked from igeligel/get-medium-stats.js
Created February 14, 2021 12:53
Show Gist options
  • Save majirosstefan/733c9862579724a8efed902d89865b7b to your computer and use it in GitHub Desktop.
Save majirosstefan/733c9862579724a8efed902d89865b7b to your computer and use it in GitHub Desktop.
medium-get-totals
const totalTypes = {
VIEWS: 2,
READS: 3,
FANS: 5
};
const getTotal = tableColumn =>
[
...document.querySelectorAll(
`td:nth-child(${tableColumn}) > span.sortableTable-number`
)
]
.map(e => parseInt(e.getAttribute("title").replace(/,/g, ""), 10))
.reduce((a, b) => a + b, 0);
console.log({
totalViews: getTotal(totalTypes.VIEWS),
totalReads: getTotal(totalTypes.READS),
totalFans: getTotal(totalTypes.FANS)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment