Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 91: Line 91:
   }
   }
})();
})();
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {


    var table = document.querySelector('.wikitable');
  const table = document.querySelector(".wikitable");
    if (!table) return;
  if (!table) return;
 
  const rows = Array.from(table.querySelectorAll("tr"));
 
  if (rows.length <= 1) return;
 
  const header = rows[0];
  const dataRows = rows.slice(1);


    function parseTime(t) {
  function parseTime(t) {
        if (!t.includes(":")) return 999999;
    if (!t || !t.includes(":")) return 999999;
        var parts = t.split(":");
    const parts = t.trim().split(":");
        return parseInt(parts[0],10) * 60 + parseInt(parts[1],10);
    return parseInt(parts[0]) * 60 + parseInt(parts[1]);
    }
  }


     var rows = Array.from(table.rows).slice(1);
  dataRows.sort((a, b) => {
     const timeA = parseTime(a.cells[3].innerText);
    const timeB = parseTime(b.cells[3].innerText);
    return timeA - timeB;
  });


    rows.sort(function(a,b){
  dataRows.forEach(row => table.appendChild(row));
        return parseTime(a.cells[3].innerText) -
              parseTime(b.cells[3].innerText);
    });


    rows.forEach(row => table.appendChild(row));
  dataRows.forEach((row, index) => {
    const rankCell = row.cells[0];


     rows.forEach(function(row, index){
     if (index === 0) rankCell.innerHTML = "🥇 1";
        row.cells[0].innerHTML =
    else if (index === 1) rankCell.innerHTML = "🥈 2";
            index === 0 ? "🥇 1" :
    else if (index === 2) rankCell.innerHTML = "🥉 3";
            index === 1 ? "🥈 2" :
    else rankCell.innerText = index + 1;
            index === 2 ? "🥉 3" :
  });
            index + 1;
    });


});
});