GitLab Raw File Fix

Add line numbers to raw files at GitLab

  1. // ==UserScript==
  2. // @name GitLab Raw File Fix
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Add line numbers to raw files at GitLab
  6. // @author Lasse Brustad
  7. // @match https://gitlab.com/*/raw/*
  8. // @match https://gitlab.*/*/raw/*
  9. // @match https://git.coolaj86.com/*/raw/*
  10. // @grant none
  11. // @locale en
  12. // ==/UserScript==
  13. // jshint esversion: 6
  14.  
  15. (() => {
  16. 'use strict';
  17.  
  18. // Get the text block
  19. let pre = document.getElementsByTagName('pre')[0];
  20.  
  21. // Split the lines into an array
  22. let arr = pre.innerText.trim().split('\n');
  23.  
  24. // Create the new text
  25. for (let i = 0; i < arr.length; i++) {
  26. arr[i] = (i + 1) + ': ' + arr[i];
  27. }
  28.  
  29. // Replace the text with the fixed text
  30. pre.innerText = arr.join('\n');
  31. })();