Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make Gist editor automatically resize based on content using a TamperMonkey script
// ==UserScript==
// @name gist-editor-resize-userscript
// @namespace https://gist.github.com/
// @version 0.1
// @description Automatically resize the gist editor for easier editing.
// @match http*://gist.github.com/*
// @copyright 2013+ Joel Day - blog.dayjo.org
// ==/UserScript==
var textareas = document.querySelectorAll('textarea.file_contents');
var span = document.createElement('div');
span.style.visibility = "hidden";
document.body.appendChild(span);
$('textarea.file-contents').keyup(function(){
span.style.width = this.offsetWidth + 'px';
span.style.fontSize = this.style.fontSize;
span.innerText = this.value;
this.style.height = span.offsetHeight + 'px';
});
@NeWbLt123
Copy link

NeWbLt123 commented Jul 10, 2014

Is this still supposed to work ?
I'm getting ERROR: Execution of script 'gist-editor-resize-userscript' failed! Cannot read property 'getDocument' of undefined

Thanks

@jm3
Copy link

jm3 commented Sep 4, 2014

@NeWbLt123 ja, same

@Dayjo
Copy link
Author

Dayjo commented Sep 23, 2014

@jm3 @NeWbLt123 - I've updated this to now at least support the normal textarea style editor (not Ace yet)

@dragon788
Copy link

dragon788 commented Jun 22, 2016

Any chance on getting this updated for Ace, or is it just a pain in the 'ace'?

@Artistan
Copy link

Artistan commented Nov 30, 2017

Recommend setting your namespace to
https://gist.github.com/Dayjo/7804066
So people can come back to this for updates 👍
https://github.com/blog/302-gist-for-greasemonkey

FYI ... errror

ERROR: Execution of script 'gist-editor-resize-userscript' failed! $ is not a function

this may be a relevant reference for a better solution
https://codemirror.net/demo/resize.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment