Splits the Reviews column into Reviews(count) and Ratings(avg) and makes the tables in all discography tabs sortable.
当前为
// ==UserScript==
// @name Metal Archives (discography pages) - Reviews column split and sortable tables
// @namespace rikkie
// @description Splits the Reviews column into Reviews(count) and Ratings(avg) and makes the tables in all discography tabs sortable.
// @include http://www.metal-archives.com/bands/*
// @version 1.4
// @grant none
// @require http://code.jquery.com/ui/1.9.1/jquery-ui.min.js
// @require https://greasyfork.org/scripts/2199-waitforkeyelements/code/waitForKeyElements.js?version=6349
// @require https://greasyfork.org/scripts/5844-tablesorter/code/TableSorter.js?version=21758
//
// This userscript uses jQuery UI, the jQuery plugin 'tablesorter' (forked by Rob Garrison (Mottie)) http://mottie.github.io/tablesorter/docs/index.html
// and the utility function 'waitForKeyElements' (https://gist.github.com/BrockA/2625891)
//
// ==/UserScript==
// STEP 1+2: SPLIT THE REVIEWS COLUMN/ADD A COLUMN /// THE NEW FUNCTION
// It appends a column to the HTML table containing the displayed discography sub-category
function appendColumn(jNode) {
var tbl = jNode[0]; // table reference
var newCell, newText;
const cols = tbl.rows[0].cells.length - 1;
var tr = tbl.tHead.children[0],
th = document.createElement('th');
th.innerHTML = "Ratings(avg)";
th.className = "ratingsCol";
tr.appendChild(th);
for (i = 1; i < tbl.rows.length; i++) {
k = tbl.rows[i].cells[cols].innerHTML; // Retrieve the content of the current cell of the Review column and store it to variable k
re1 = /<a [^>]*>[^(]*[(]([^)]+)/ ; // (RegEx which matches the 'Ratings' percentage(incl.the % symbol)
l = re1.exec(k); // (Execute the RegEx and store it to variable l)
if (re1.test(k) != 0){ // If the RegEx has matches, (only) then create new cells with...
re0 = /(<a [^>]*>)[0-9]*[^(]/ ; // (RegEx which matches the reviews URL)
url = re0.exec(k); // (Execute the RegEx and store it to variable url)
newCell = tbl.rows[i].insertCell(-1);
newCell.innerHTML = url[1] + l[1] + '</url>'; // ...the Ratings percentage (which is also a link to the Reviews)...
re2 = /<a [^>]*>([0-9]*)[^(]/ ; // (RegEx which matches the 'Reviews' number)
m = re2.exec(k); // (Execute the RegEx and store it to variable m)
newCell = tbl.rows[i].cells[cols]; //
newCell.innerHTML = url[1] + m[1] + '</url>'; // ...and the Reviews number (which is also a link to the Reviews)
}
}
}
// STEP 3: MAKE THE DISCOGRAPHY TABLE SORTABLE (using the jQuery plugin "tablesorter")
// (based on http://mottie.github.io/tablesorter/docs/index.html#Getting-Started)
// Calling this sorting() function causes 'tablesorter' to make the Discography table sortable (when the document is loaded//i.e. binds the function to the document.ready event)
function sorting(){
$('.display.discog').tablesorter();
}
// Wait for the discography table to be completely loaded, then split+append column. After that
// wait for the new Ratings column to appear (ie the the column splitting to be completed), then make the table sortable
waitForKeyElements (".display.discog", appendColumn);
waitForKeyElements (".ratingsCol", sorting);
// sorting();
// as long as you are viewing one of the sub-tabs of DISCOGRAPHY, split+append column and make current (sub)table sortable
do{
waitForKeyElements (".display.discog", appendColumn);
waitForKeyElements (".ratingsCol", sorting);
}
while (jNode[0].parentNode == ('.display.discog'));