Skip to content

Instantly share code, notes, and snippets.

@nhoizey
Last active May 29, 2020 10:33
Show Gist options
  • Save nhoizey/007f74bedcecf7dc59f2906207827807 to your computer and use it in GitHub Desktop.
Save nhoizey/007f74bedcecf7dc59f2906207827807 to your computer and use it in GitHub Desktop.
Compute faves/views ratio on Flickr stats pages
javascript:(function()%7B((document)%20%3D%3E%20%7Bdocument.querySelectorAll('.row').forEach(row%20%3D%3E%20%7Blet%20views%20%3D%20parseInt(row.querySelector('td%3Anth-child(3)').innerText.replace('%2C'%2C%20'')%2C%2010)%3Blet%20faves%20%3D%20parseInt(row.querySelector('td%3Anth-child(4)').innerText.replace('%2C'%2C%20'')%2C%2010)%3Blet%20ratio%20%3D%20Math.round(10000%20*%20faves%20%2F%20views)%20%2F%20100%3Brow.querySelector('td%3Anth-child(4)').innerText%20%3D%20row.querySelector('td%3Anth-child(4)').innerText%20%2B%20'%20('%20%2B%20ratio%20%2B%20'%20%25)'%3B%7D)%3B%7D)(window.document)%7D)()
// Run this on a stats page
((document) => {
document.querySelectorAll('.row').forEach(row => {
let views = parseInt(row.querySelector('td:nth-child(3)').innerText.replace(',', ''), 10);
let faves = parseInt(row.querySelector('td:nth-child(4)').innerText.replace(',', ''), 10);
let ratio = Math.round(10000 * faves / views) / 100;
row.querySelector('td:nth-child(4)').innerText = row.querySelector('td:nth-child(4)').innerText + ' (' + ratio + ' %)';});
})(window.document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment