Gist Edit Resize

Gist enhancements with collapsible files and larger editor area

当前为 2023-02-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Gist Edit Resize
  3. // @namespace cvladan.com
  4. // @match *://gist.github.com/*
  5. // @run-at document-start
  6. // @inject-into content
  7. // @grant none
  8. // @version 1.0
  9. // @license MIT
  10. // @author -
  11. // @description Gist enhancements with collapsible files and larger editor area
  12. // ==/UserScript==
  13.  
  14. var css = `
  15.  
  16. .CodeMirror {
  17. height: auto !important;
  18. }
  19.  
  20. .file.show-code:has(.CodeMirror.CodeMirror-focused) {
  21. outline: 3px solid gray;
  22. }
  23.  
  24. `
  25.  
  26. // Inject CSS in document head
  27. //
  28. function injectStyle(css) {
  29. var doc = document;
  30. var script = document.createElement('style');
  31. script.textContent = css;
  32.  
  33. var where = doc.getElementsByTagName ('head')[0] || doc.body || doc.documentElement;
  34. where.appendChild(script);
  35. }
  36.  
  37. injectStyle(css)
  38.  
  39.  
  40. // Toggle buttons to every file
  41. // Plain JavaScript rewrite of https://greasyfork.org/en/scripts/31700-togglegist
  42. //
  43. document.addEventListener('DOMContentLoaded', function() {
  44. const fileBoxes = document.querySelectorAll('.file-box');
  45.  
  46. fileBoxes.forEach(function(fileBox) {
  47. const btn = document.createElement('a');
  48. btn.classList.add('btn', 'btn-sm', 'git-toggle-file');
  49. btn.href = '#';
  50. btn.textContent = 'Toggle';
  51.  
  52. btn.addEventListener('click', function(e) {
  53. e.preventDefault();
  54. const wrapper = e.target.closest('.file').querySelector('.blob-wrapper, .blob');
  55. wrapper.hidden = !wrapper.hidden;
  56. })
  57.  
  58. fileBox.querySelector('.file-actions .btn').parentElement.appendChild(btn);
  59. })
  60. });