Skip to content

Instantly share code, notes, and snippets.

@erickoledadevrel
Last active August 29, 2015 14:10
Show Gist options
  • Save erickoledadevrel/64773cacd01b198545cf to your computer and use it in GitHub Desktop.
Save erickoledadevrel/64773cacd01b198545cf to your computer and use it in GitHub Desktop.
The Google Drive SDK console only allows you to enter MIME types and file extensions one at a time. This script allows you to enter a comma-separated list of values into a text box and then have it split into multiple text boxes automatically.
(function() {
// Include jQuery.
var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-2.1.1.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
var sections = [
'Default MIME Types',
'Default File Extensions',
'Secondary MIME Types',
'Secondary File Extensions'
];
sections.forEach(function(section) {
var header = $('h4:contains("' + section + '")');
var inputs = header.nextUntil('h4').find('input');
var values = inputs.get().reduce(function(result, input) {
var value = $(input).val();
var parts = value.split(',');
if (parts.length > 1) {
$(input).val(parts.shift());
result = result.concat(parts);
}
return result;
}, []);
var keypressEvent = jQuery.Event('keypress', {which: 65, keyCode: 65});
// Dummy handler is added so .trigger() will fire correctly.
var keypressHandler = function() {};
values.forEach(function(value) {
header.nextUntil('h4').find('input:last')
.val(value)
.keypress(keypressHandler)
.trigger(keypressEvent);
});
});
})();
// Compressed
// (function(){var e=document.createElement("script");e.src="https://code.jquery.com/jquery-2.1.1.min.js";e.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(e);var t=["Default MIME Types","Default File Extensions","Secondary MIME Types","Secondary File Extensions"];t.forEach(function(e){var t=$('h4:contains("'+e+'")');var n=t.nextUntil("h4").find("input");var r=n.get().reduce(function(e,t){var n=$(t).val();var r=n.split(",");if(r.length>1){$(t).val(r.shift());e=e.concat(r)}return e},[]);var i=jQuery.Event("keypress",{which:65,keyCode:65});var s=function(){};r.forEach(function(e){t.nextUntil("h4").find("input:last").val(e).keypress(s).trigger(i)})})})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment