Skip to content

Instantly share code, notes, and snippets.

@kovid-r
Forked from igeligel/get-medium-stats.js
Created January 9, 2022 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kovid-r/2bb3b3820dc6c8bcdbe9633407a08f69 to your computer and use it in GitHub Desktop.
Save kovid-r/2bb3b3820dc6c8bcdbe9633407a08f69 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