UnipaSorter

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

当前为 2016-04-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        UnipaSorter
// @namespace   magicleonSorter
// @include     http://immaweb.unipa.it/immaweb/private/docenti/esami/include/contenutiInsegnamentoMaterialeDidattico.seam*
// @version     1
// @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');
//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());
}