Last active
October 17, 2017 14:44
-
-
Save simonwjackson/18650902fe720bf385255d05efdf7245 to your computer and use it in GitHub Desktop.
Vimify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Vimify | |
// @namespace http://miniarray.com | |
// @version 0.1 | |
// @description Vimify textarea inputs | |
// @author You | |
// @match https://glitch.com/edit/* | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict' | |
var makeCursorFat = function() { | |
var style = document.createElement('style'); | |
style.textContent = | |
'div.CodeMirror div.CodeMirror-cursor { ' + | |
'width: auto; ' + | |
'border: 0; ' + | |
'background: transparent; ' + | |
'background: rgba(0, 200, 0, .4); ' + | |
'} '; | |
document.head.appendChild(style); | |
} | |
var addScript = function(callback) { | |
var scr = document.createElement('script'); | |
scr.src = 'https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.30.0/keymap/vim.js'; | |
scr.onload = callback; | |
document.head.appendChild(scr); | |
} | |
var retryInterval = 1000; | |
var vimify = function () { | |
var editorElement = document.querySelector('#text-editor > div.CodeMirror'); | |
if (editorElement) { | |
editorElement.CodeMirror.options.keyMap = 'vim'; | |
editorElement.CodeMirror.options.showCursorWhenSelecting = 'vim'; | |
makeCursorFat(); | |
console.log('VIMification complete!'); | |
} else{ | |
retryInterval = retryInterval * 2; | |
if (retryInterval < 20000) { | |
console.log('Retrying to VIMify... ' + retriesLeft); | |
window.setTimeout(vimify, retryInterval); | |
} | |
return; | |
} | |
}; | |
addScript(vimify); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment