Skip to content

Instantly share code, notes, and snippets.

@azu
Created February 15, 2015 13:55
Show Gist options
  • Save azu/90863c5082dd81a49fa4 to your computer and use it in GitHub Desktop.
Save azu/90863c5082dd81a49fa4 to your computer and use it in GitHub Desktop.
add placeholder textarea which sync with ACE Editor to GitHub.
// ==UserScript==
// @name github:place-holder-textarea
// @namespace http://efcl.info/
// @description place holder textare
// @include https://github.com/*/*/edit/*/*
// @include https://github.com/*/*/new/*/*
// @version 1
// @grant none
// @run-at document-end
// ==/UserScript==
var div = document.querySelector("div.ace_editor");
var editor = ace.edit(div);
function onChange(textArea, callback){
textArea.addEventListener('input', function(event) {
callback(event.target.value);
}, false);
textArea.addEventListener('change', function(event) {
callback(event.target.value);
}, false);
textArea.addEventListener('blur', function(event) {
callback(event.target.value);
}, false);
}
function createPlaceHolder(aceEditor){
var textArea = document.createElement("textarea");
textArea.setAttribute("style", `
position: absolute;
overflow: auto;
top: 80px;
right: 0;
`);
textArea.value = aceEditor.getValue();
onChange(textArea, function(value){
aceEditor.setValue(value);
});
return textArea;
}
var placeHolderTextArea = createPlaceHolder(editor);
editor.on('change', function(event){
placeHolderTextArea.value = editor.getValue();
});
document.body.appendChild(placeHolderTextArea);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment