Created
April 27, 2016 04:16
-
-
Save Kobold/2e7eb69f3c4dd6513742cd78eea13dba to your computer and use it in GitHub Desktop.
Revisions
-
Kobold created this gist
Apr 27, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ 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 hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ 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); } }); } })();