Skip to content

Instantly share code, notes, and snippets.

@anevins12
Last active January 23, 2018 16:05
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 anevins12/d59e107a163aed5291409e682ebad278 to your computer and use it in GitHub Desktop.
Save anevins12/d59e107a163aed5291409e682ebad278 to your computer and use it in GitHub Desktop.
WordPress.org Reviews Sort
// ==UserScript==
// @name WordPress.org Reviews Sort
// @description Sorts reviews by the number of replies
// @namespace WordPress_reviews_sort
// @include *://*wordpress.org/support/forum/reviews/*
// @version 1.0.0
// @updateURL https://gist.githubusercontent.com/anevins12/d59e107a163aed5291409e682ebad278/raw/78a80c844723c8fea7edc55fb6b7bbec76bc0fbc/wordpress-sort-reviews.js
// @downloadURL https://gist.githubusercontent.com/anevins12/d59e107a163aed5291409e682ebad278/raw/78a80c844723c8fea7edc55fb6b7bbec76bc0fbc/wordpress-sort-reviews.js
// @grant none
// @author anevins12
// ==/UserScript==
(function() {
'use strict';
var $ = jQuery,
template = $('.bbp-body'),
topicsToSort = [],
sortCriteria = 0,
dataAttr = 'data-sort-value',
topics;
if (template.length !== 0) {
topics = template.find('> ul:not(".sticky")');
topics.each(function() {
var topic = $(this),
sortCriterion = $('.bbp-topic-reply-count', topic),
sortValue = parseInt(sortCriterion.text());
if (sortValue > sortCriteria) {
sortCriterion.css({
'color': 'deeppink',
'fontWeight': 700
});
topic.attr(dataAttr, sortValue);
topicsToSort.push(topic);
topic.remove();
}
});
if (topicsToSort.length !== 0) {
topicsToSort.sort(function(a, b){
var aVal = parseInt(a.attr(dataAttr)),
bVal = parseInt(b.attr(dataAttr));
return bVal - aVal;
});
template.prepend(topicsToSort);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment