Gist Edit Resize

Gist enhancements with collapsible files and larger editor area

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Gist Edit Resize
// @namespace   cvladan.com
// @match       *://gist.github.com/*
// @run-at      document-start
// @inject-into content
// @grant       none
// @version     1.0
// @license MIT
// @author      -
// @description Gist enhancements with collapsible files and larger editor area
// ==/UserScript==

var css = `

  .CodeMirror {
    height: auto !important;
  }

  .file.show-code:has(.CodeMirror.CodeMirror-focused) {
    outline: 3px solid gray;
  }

`

// Inject CSS in document head
//
function injectStyle(css) {
	var doc = document;
  var script = document.createElement('style');
  script.textContent = css;

  var where = doc.getElementsByTagName ('head')[0] || doc.body || doc.documentElement;
  where.appendChild(script);
}

injectStyle(css)


// Toggle buttons to every file
// Plain JavaScript rewrite of https://greasyfork.org/en/scripts/31700-togglegist
//
document.addEventListener('DOMContentLoaded', function() {
  const fileBoxes = document.querySelectorAll('.file-box');

  fileBoxes.forEach(function(fileBox) {
    const btn = document.createElement('a');
    btn.classList.add('btn', 'btn-sm', 'git-toggle-file');
    btn.href = '#';
    btn.textContent = 'Toggle';

    btn.addEventListener('click', function(e) {
      e.preventDefault();
      const wrapper = e.target.closest('.file').querySelector('.blob-wrapper, .blob');
      wrapper.hidden = !wrapper.hidden;
    })

    fileBox.querySelector('.file-actions .btn').parentElement.appendChild(btn);
  })
});