Better GitHub Gists Code Area

Resizes the editor to fit the viewport height, subtracting 500px. Handles window resizing.

  1. // ==UserScript==
  2. // @name Better GitHub Gists Code Area
  3. // @namespace https://github.com/palemoky
  4. // @version 20250325
  5. // @description Resizes the editor to fit the viewport height, subtracting 500px. Handles window resizing.
  6. // @author Palemoky
  7. // @license Apache
  8. // @match https://gist.github.com/*
  9. // @icon https://raw.githubusercontent.com/homarr-labs/dashboard-icons/refs/heads/main/webp/github.webp
  10. // @run-at document-body
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. 'use strict';
  15.  
  16. function adjustCodeMirrorHeight() {
  17. requestAnimationFrame(() => {
  18. const codeMirrorDiv = document.querySelector('.CodeMirror');
  19.  
  20. if (codeMirrorDiv && codeMirrorDiv.CodeMirror) {
  21. const newHeight = document.documentElement.clientHeight - 457;
  22. codeMirrorDiv.style.height = Math.max(0, newHeight) + 'px';
  23. codeMirrorDiv.CodeMirror.refresh();
  24. }
  25. });
  26. }
  27.  
  28. function debounce(func, wait) {
  29. let timeout;
  30. return function(...args) {
  31. const context = this;
  32. clearTimeout(timeout);
  33. timeout = setTimeout(() => func.apply(context, args), wait);
  34. };
  35. }
  36.  
  37. const debouncedAdjustCodeMirrorHeight = debounce(adjustCodeMirrorHeight, 200);
  38.  
  39. setTimeout(debouncedAdjustCodeMirrorHeight, 100);
  40.  
  41. const observer = new MutationObserver(debouncedAdjustCodeMirrorHeight);
  42. observer.observe(document.body, { childList: true, subtree: true });
  43.  
  44. window.addEventListener('resize', debouncedAdjustCodeMirrorHeight);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址