Skip to content

Instantly share code, notes, and snippets.

@DarkPark
Created May 28, 2021 18:23
Show Gist options
  • Save DarkPark/6a9e54de90d4280351f24ed7089d498a to your computer and use it in GitHub Desktop.
Save DarkPark/6a9e54de90d4280351f24ed7089d498a to your computer and use it in GitHub Desktop.
Array.prototype.slice.call(document.querySelectorAll('.book-row')).forEach($book => {
const stats = $book.querySelector('.book-stats');
if ( stats ) {
const views = Number(stats.firstElementChild.dataset.hint.replace('Просмотры · ', '').replace(/ /g, ''));
const likes = Number(stats.firstElementChild.nextElementSibling.dataset.hint.replace('Понравилось · ', '').replace(/ /g, ''));
const $info = document.createElement('span');
const ratio = Math.floor(views/likes);
//console.log(ratio);
$info.textContent = Math.floor(views/likes);
$info.style.fontWeight = 'bold';
if ( ratio < 50 ) {
$info.style.color = 'green';
}
if ( ratio > 100 ) {
$book.style.display = 'none';
}
stats.insertBefore($info, stats.firstElementChild);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment