Metal Archives (discography pages) - Reviews column split and sortable tables

Splits the Reviews column into Reviews(count) and Ratings(avg) and makes the tables in all discography tabs sortable.

目前為 2015-04-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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.3.2
// @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 and it's plugin "tablesorter" (forked by Rob Garrison (Mottie)) http://mottie.github.io/tablesorter/docs/index.html
//
// ==/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 only the number(and the %) inside the parentheses
        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 each cell with the result of the RegEx
            newCell = tbl.rows[i].insertCell(-1);
            newCell.innerHTML = l[1];            
            re2 = /<a [^>]*>([0-9]*)[^(]/ ;   // RegEx which matches only the number before the parentheses
            m = re2.exec(k);                  // Execute the RegEx and store it to variable m
            newCell = tbl.rows[i].cells[cols];
            newCell.innerHTML = m[1];          
            }
        
    }    
}





//  STEP 3: MAKE THE TABLE SORTABLE  (using jQuery and it's plugin "tablesorter")
// ( based on http://mottie.github.io/tablesorter/docs/index.html#Getting-Started & http://stackoverflow.com/a/18867406/3231411 )
// It inserts these two inline scripts in the <HEAD> of the page and includes jquery on this file
function sorting(){
    $('.display.discog').tablesorter();  
}
    


// Wait for the discography table to be completely loaded, then split+append column. After that, do the same in order the table to become sortable
waitForKeyElements (".display.discog", appendColumn);    
waitForKeyElements (".ratingsCol", sorting); 

// as long as you are viewing one of the sub-tabs of DISCOGRAPHY, split+append column
do{
    waitForKeyElements (".display.discog", appendColumn);    
    waitForKeyElements (".ratingsCol", sorting);   
    // sorting();
}
while (jNode[0].parentNode ==  ('.display.discog'));