Gitlab Copy Commit Link Instead of SHA

This is a Tampermonkey user script that enhances the Gitlab user interface by adding a button that copies the commit link to the clipboard instead of just the commit SHA.

  1. // ==UserScript==
  2. // @name Gitlab Copy Commit Link Instead of SHA
  3. // @license MIT
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.1
  6. // @description This is a Tampermonkey user script that enhances the Gitlab user interface by adding a button that copies the commit link to the clipboard instead of just the commit SHA.
  7. // @author You
  8. // @match https://gitlab.com/*/commits/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=gitlab.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. document.querySelectorAll('li.commit').forEach(function (commit) {
  16. let commitLink = commit.querySelector('a.item-title').getAttribute('href');
  17. let avatarCell = commit.querySelector('div.avatar-cell');
  18. // add a button to copy the commit link
  19. let copyBtn = commit.querySelector('button[aria-label="Copy commit SHA"]');
  20. // duplicate the button
  21. let copyBtnClone = copyBtn.cloneNode(true);
  22. // add the clone to the avatar cell
  23. avatarCell.appendChild(copyBtnClone);
  24. // apply margin-right: 0.8rem; margin-top: 0.2rem;
  25. copyBtnClone.style.marginRight = '0.8rem';
  26. copyBtnClone.style.marginTop = '0.25rem';
  27. let commitUrl = window.location.origin + commitLink;
  28. copyBtnClone.setAttribute('data-clipboard-text', commitUrl);
  29. });
  30. })();