Created
April 27, 2016 04:16
-
-
Save Kobold/2e7eb69f3c4dd6513742cd78eea13dba to your computer and use it in GitHub Desktop.
Bookmarklets to sort arbitrary Goodreads views by popularity and rating!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(() => { | |
if (window.tinysort === undefined) { | |
var script = document.createElement('script'); | |
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/tinysort/2.3.0/tinysort.min.js'; | |
script.onload = function() { | |
sortGoodreads(); | |
}; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} else { | |
sortGoodreads(); | |
} | |
function getRatingCount(ratingString) { | |
var countString = /([\d,]+) rating/.exec(ratingString)[1]; | |
return parseInt(countString.replace(/,/g, ''), 10); | |
} | |
function sortGoodreads() { | |
var listSelector = '.tableList tr[itemtype="http://schema.org/Book"]'; | |
tinysort(listSelector, { | |
order: 'desc', | |
sortFunction: (a, b) => { | |
var countA = getRatingCount(jQuery(a.elm).find('.minirating').text()); | |
var countB = getRatingCount(jQuery(b.elm).find('.minirating').text()); | |
return countA === countB ? | |
0 : | |
(countA > countB ? 1 : -1); | |
} | |
}); | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(() => { | |
if (window.tinysort === undefined) { | |
var script = document.createElement('script'); | |
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/tinysort/2.3.0/tinysort.min.js'; | |
script.onload = function() { | |
sortGoodreads(); | |
}; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} else { | |
sortGoodreads(); | |
} | |
function getRatingCount(ratingString) { | |
var rating = /([\d.]+) avg rating/.exec(ratingString)[1]; | |
return parseFloat(rating); | |
} | |
function sortGoodreads() { | |
var listSelector = '.tableList tr[itemtype="http://schema.org/Book"]'; | |
tinysort(listSelector, { | |
order: 'desc', | |
sortFunction: (a, b) => { | |
var countA = getRatingCount(jQuery(a.elm).find('.minirating').text()); | |
var countB = getRatingCount(jQuery(b.elm).find('.minirating').text()); | |
return countA === countB ? | |
0 : | |
(countA > countB ? 1 : -1); | |
} | |
}); | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment