Skip to content

Instantly share code, notes, and snippets.

@Kobold
Created April 27, 2016 04:16
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 Kobold/2e7eb69f3c4dd6513742cd78eea13dba to your computer and use it in GitHub Desktop.
Save Kobold/2e7eb69f3c4dd6513742cd78eea13dba to your computer and use it in GitHub Desktop.
Bookmarklets to sort arbitrary Goodreads views by popularity and rating!
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);
}
});
}
})();
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