Make table headers sticky

05/08/2025, 13:00:14

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

// ==UserScript==
// @name        Make table headers sticky
// @namespace   Violentmonkey Scripts
// @match       https://*/wiki/*
// @match       https://techlore.tech/*
// @match       https://wiki.*/*
// @match       https://*freie-messenger*/*
// @grant       none
// @version     1.1
// @author      SHA
// @license     GNU GPLv3
// @description 05/08/2025, 13:00:14
// ==/UserScript==

// TODO: use jQuery and $(...).floatThead() instead because "display: sticky" doesn't work with "overflow-x: auto".

window.addEventListener("load", (event) => {

  setTimeout(() => {
    const tables = document.querySelectorAll("table:not(.infobox):not(.sidebar)"); // exclude fact sheets on wikipedia
    tables.forEach(table => {
      table.style.display = "table";
      const header = table.querySelector("tr:first-of-type");
      header.style.position = "sticky";
      header.style.top = "0";
      header.style.zIndex = "10000";
      const rowHeaders = table.querySelectorAll("tbody th");
      rowHeaders.forEach(th => {
        th.style.position = "sticky";
        th.style.left = "0";
        th.style.zIndex = "10000";
      });
    });

    // for https://techlore.tech/vpn/
    const grids = document.querySelectorAll("*[role=grid]");
    grids.forEach(grid => {
      grid.style.display = "initial";
      const header = grid.querySelector("*[role=rowgroup]:first-of-type");
      header.style.position = "sticky";
      header.style.top = "0";
      header.style.zIndex = "10000";
    });
  }, 500);
});