UnipaSorter

This script sorts the table entry of the download section in the students portal from the University of Palermo

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        UnipaSorter
// @namespace   magicleonSorter
// @include     https://immaweb.unipa.it/immaweb/private/docenti/esami/include/contenutiInsegnamentoMaterialeDidattico.seam*
// @version     3
// @grant       none
// @description This script sorts the table entry of the download section in the students portal from the University of Palermo
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
//@require http://tablesorter.com/addons/pager/jquery.tablesorter.pager.js
// ==/UserScript==
// Author: Antonello Galipò

//prendo la tabella di interesse
//tableRows = $('table[id="j_id71:materialeDidatticoList"] tr');
//è stata riscontrata una variazione dell'ID della tabella, ho modificato la presa del riferimento alla tabella di interesse col seguente statement
tableRows = $('table:has(thead) tr')
//elimino l'heading
tableRows.splice(0, 1);
//banale bubblesort per ordinare le righe cronologicamente
var swapped;
do {
  swapped = false;
  for (var i = 0; i < tableRows.length - 1; i++) {
    if (getDateFromRow(i) < getDateFromRow(i + 1)) {
      //console.log("swapping");
      swapRows(tableRows.eq(i), tableRows.eq(i + 1));
      swapped = true;
    }
  }
} while (swapped);


//swappa due <tr>
function swapRows(x, y) {
  xhtml = x.html();
  x.html(y.html());
  y.html(xhtml);
}
//converte una stringa in data
function getDateFromString(dateString) {
  // console.log("input = " + dateString);
  x = dateString.split(' ');
  y = x[0].split('/');
  // console.log("x = " + x);
  // console.log("y = " + y);
  date = y[1] + '/' + y[0] + '/' + y[2] + ' ' + x[1];
  // console.log("date = " + date);
  return new Date(date);
}
//prende la data come stringa dalla colonna di pertinenza della riga n-esima
function getDateFromRow(n) {
  console.log('per n = ' + n);
  return getDateFromString(tableRows.eq(n).children().eq(0).text().replace(/\s+/g, ' ').trim());
}