Skip to content

Instantly share code, notes, and snippets.

@digitalfiz
Created June 20, 2016 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitalfiz/ca7bf3b05d17b479388029b1bbb2827f to your computer and use it in GitHub Desktop.
Save digitalfiz/ca7bf3b05d17b479388029b1bbb2827f to your computer and use it in GitHub Desktop.
Aced out GameServers.com Config editor
// ==UserScript==
// @name Aced out GameServers.com Config editor
// @namespace http://tampermonkey.net/
// @version 0.1
// @description This script adds the ace editor to the config editor on gameservers.com
// @author digitalfiz <https://twitter.com/digitalfiz>
// @match https://my.gameservers.com/home/subscription_info.php?view=server_configuration&*
// @grant none
// ==/UserScript==
function buildEditor(syntax) {
var textarea = $('textarea[name="advanced_editor_content"]');
// create div with the editors contents
$(textarea).before('<div id="editor">' + $(textarea).text() + '</div>');
// make it purdy
$("#editor").css('width', '100%');
$("#editor").css('height', '400px');
$("#editor").css('margin-top', '10px');
// Setup editor on new div
var editor = ace.edit('editor');
editor.setTheme('ace/theme/tomorrow_night');
// Add syntax highlighting
editor.getSession().setMode('ace/mode/' + syntax);
// Loop changes back to the textarea
editor.getSession().on('change', function () {
textarea.val(editor.getSession().getValue());
});
// Now lets hide the textarea
$(textarea).hide();
}
(function () {
'use strict';
var sel = $('select[name="GMCONFIGID"] option:selected').text();
var syntax = 'plain_text';
if (sel.indexOf('.ini') >= 0) {
syntax = 'ini';
} else if (sel.indexOf('Server Command Line') >= 0) {
syntax = 'sh';
}
// Load up ace!
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.3/ace.js').done(function( script, textStatus ) {
// remote script has loaded
console.log('loaded ace');
buildEditor(syntax);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment