GitLab Raw File Fix

Add line numbers to raw files at GitLab

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         GitLab Raw File Fix
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Add line numbers to raw files at GitLab
// @author       Lasse Brustad
// @match        https://gitlab.com/*/raw/*
// @match        https://gitlab.*/*/raw/*
// @match        https://git.coolaj86.com/*/raw/*
// @grant        none
// @locale       en
// ==/UserScript==
// jshint esversion: 6

(() => {
    'use strict';

    // Get the text block
    let pre = document.getElementsByTagName('pre')[0];

    // Split the lines into an array
    let arr = pre.innerText.trim().split('\n');

    // Create the new text
    for (let i = 0; i < arr.length; i++) {
        arr[i] = (i + 1) + ': ' + arr[i];
    }

    // Replace the text with the fixed text
    pre.innerText = arr.join('\n');
})();