Skip to content

Instantly share code, notes, and snippets.

@vyach-vasiliev
Created October 26, 2024 18:12
Show Gist options
  • Save vyach-vasiliev/73ecee8fa953087080a7e38562c5cd7d to your computer and use it in GitHub Desktop.
Save vyach-vasiliev/73ecee8fa953087080a7e38562c5cd7d to your computer and use it in GitHub Desktop.
Cacl turth

Counting score of the latest -N reviews on OZON.ru

// upd 26/10/2024
let userScores = Array.from(document.querySelectorAll('div[data-widget="webListReviews"] div'))
  .map(div => Array.from(div.children).filter(child => child.tagName === 'svg' && child.style.color === 'rgb(255, 168, 0)').length)
  .filter(score => score > 0)
  .slice(0, 10); // Get the first 10 scores

const totalScore = Math.max(1, Math.min(userScores.reduce((acc, score) => acc + score, 0) / userScores.length, 5));

console.log(totalScore);

bookmarklet (with interactive score prompt)

javascript:var userScores = Array.from(document.querySelectorAll('div[data-widget="webListReviews"] div')).map(div => Array.from(div.children).filter(child => child.tagName === 'svg' && child.style.color === 'rgb(255, 168, 0)').length).filter(score => score > 0).slice(0, prompt(`How many recent reviews should be taken for rating calculation?`, 10));var totalScore = Math.max(1, Math.min(userScores.reduce((acc, score) => acc + score, 0) / userScores.length, 5));alert(`Score is ${totalScore}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment