Resizable Table Columns & Replace Link Text

Let user resize table columns by dragging the header edges & replace anchor text with its title attribute

Από την 21/02/2025. Δείτε την τελευταία έκδοση.

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

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

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

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

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

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

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

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.

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

// ==UserScript==
// @name         Resizable Table Columns & Replace Link Text
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @author       aspen138
// @description  Let user resize table columns by dragging the header edges & replace anchor text with its title attribute
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Insert some CSS for the column "grip" that we'll add to each header
    const style = document.createElement('style');
    style.textContent = `
      .column-resize-grip {
        position: absolute;
        top: 0;
        right: 0;
        width: 6px;       /* Thicker area for easier dragging */
        height: 100%;
        cursor: col-resize;
        user-select: none;
      }
      th.resizable-header {
        position: relative;
      }
    `;
    document.head.appendChild(style);

    /**
     * Attach grips to each table header so we can drag the column widths.
     * @param {HTMLTableElement} table  A table element to attach resizing.
     */
    function makeColumnsResizable(table) {
        const headers = table.querySelectorAll('th');
        if (!headers.length) return;

        headers.forEach((header) => {
            header.classList.add('resizable-header');
            // Avoid adding multiple grips if script runs again
            if (header.querySelector('.column-resize-grip')) return;

            const grip = document.createElement('div');
            grip.className = 'column-resize-grip';
            header.appendChild(grip);

            grip.addEventListener('mousedown', startDragging);
        });

        function startDragging(event) {
            event.preventDefault();
            event.stopPropagation();

            const headerEl = event.target.parentElement;
            const startX = event.clientX;
            const startWidth = headerEl.offsetWidth;

            document.addEventListener('mousemove', onDrag);
            document.addEventListener('mouseup', stopDragging);

            function onDrag(e) {
                const dx = e.clientX - startX;
                headerEl.style.width = `${startWidth + dx}px`;
            }

            function stopDragging() {
                document.removeEventListener('mousemove', onDrag);
                document.removeEventListener('mouseup', stopDragging);
            }
        }
    }

    /**
     * Replace the truncated link text with its full "title" attribute.
     * @param {HTMLTableElement} table A table element containing anchors with a title attribute.
     */
    function replaceLinkTextWithTitle(table) {
        const anchors = table.querySelectorAll('a[title]');
        anchors.forEach(anchor => {
            anchor.textContent = anchor.getAttribute('title');
        });
    }

    window.addEventListener('load', function() {
        // Modify the selector below to match your table's selector
        const table = document.querySelector('.t-tablelist');
        if (table) {
            makeColumnsResizable(table);
            replaceLinkTextWithTitle(table);
        }
    });
})();