Pretty print your GitLab Snippet

try to take over the world!

目前为 2020-03-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Pretty print your GitLab Snippet
  3. // @namespace dkt.pprint.gitlabsnippet
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://*/snippets/*
  8. // @run-at document-end
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. if (!document.querySelector('.navbar-gitlab')) return;
  15.  
  16. const buttonWrapper = unsafeWindow.document.querySelector('.detail-page-header-actions > div');
  17. const activateBtn = document.createElement('a');
  18. activateBtn.className = 'btn btn-grouped';
  19. activateBtn.href = '#';
  20. activateBtn.textContent = 'Pretty Print';
  21. buttonWrapper.append(activateBtn);
  22.  
  23. activateBtn.addEventListener('click', (e) => {
  24. e.preventDefault();
  25.  
  26. document.querySelector('.navbar-gitlab').remove();
  27. document.querySelector('.layout-page > .content-wrapper > .alert-wrapper').remove();
  28. document.querySelector('#content-body > .detail-page-header').remove();
  29. document.querySelector('#content-body small.edited-text').remove();
  30. document.querySelector('#content-body .content-component-block').remove();
  31. document.querySelector('#content-body .personal-snippets').remove();
  32. document.querySelector('#content-body #notes').remove();
  33.  
  34. window.print()
  35. });
  36.  
  37. })();