Generate Table of Contents for ar5iv

Generates a table of contents for ar5iv papers, displayed on the left side of the page.

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

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

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name        Generate Table of Contents for ar5iv
// @namespace   awyugan
// @description Generates a table of contents for ar5iv papers, displayed on the left side of the page.
// @match    https://ar5iv.labs.arxiv.org/*
// @license MIT
// @version     1.0
// @grant       none
// ==/UserScript==

(function() {
    'use strict';

    // Create a div for the table of contents
    var tocDiv = document.createElement('div');
    tocDiv.style.position = 'fixed';
    tocDiv.style.left = '0';
    tocDiv.style.top = '0';
    tocDiv.style.border = '1px solid black';
    tocDiv.style.padding = '10px';
    tocDiv.style.backgroundColor = '#f9f9f9';
    tocDiv.style.width = '200px';
    tocDiv.style.height = '100vh';
    tocDiv.style.overflow = 'auto';

    // Create a title for the table of contents
    var tocTitle = document.createElement('h2');
    tocTitle.textContent = 'Table of Contents';
    tocDiv.appendChild(tocTitle);

    // Get all h1, h2, h3, h4, h5 and h6 elements
    var headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');

    // Create a link for each heading and add it to the table of contents
    headings.forEach(function(heading, index) {
        var link = document.createElement('a');
        link.textContent = heading.textContent;
        link.href = '#heading' + index;

        // Add an id to the heading so the link can refer to it
        heading.id = 'heading' + index;

        // Adjust link style based on heading level
        var headingLevel = parseInt(heading.tagName[1]);
        link.style.display = 'block';
        link.style.textIndent = (headingLevel - 1) * 10 + 'px';
        link.style.fontSize = (7 - headingLevel) + 'pt';

        tocDiv.appendChild(link);
    });

    // Add the table of contents to the body
    document.body.appendChild(tocDiv);
})();