Skip to content

Instantly share code, notes, and snippets.

@RickyCook
Last active August 29, 2015 14:16
Show Gist options
  • Save RickyCook/b428f7f72945d21d5cf9 to your computer and use it in GitHub Desktop.
Save RickyCook/b428f7f72945d21d5cf9 to your computer and use it in GitHub Desktop.
Fill AWS tags based on a JSON hash, obtained from user prompt
(function($, c) {
var rootObject = $('table:visible:contains("Create Tag")').first(),
createButton = $('button:contains("Create Tag")', rootObject).first(),
inputsKey = $('input[name="key"]', rootObject),
inputsValue = $('input[name="value"]', rootObject),
tags = $.parseJSON(prompt('JSON tag values')),
tagsKeys = Object.keys(tags);
if (tagsKeys.length > inputsKey.length) {
for (var i = 0; i < tagsKeys.length - inputsKey.length; i++) {
createButton.click();
}
inputsKey = $('input[name="key"]', rootObject);
inputsValue = $('input[name="value"]', rootObject);
}
inputsKey.each(function(i, inputKey) {
var inputValue = inputsValue[i],
tagKey = tagsKeys[i],
tagValue = tags[tagKey];
$(inputKey).val(tagKey);
$(inputValue).val(tagValue);
})
})(jQuery, console)
javascript:(function($,c){var rootObject=$('table:visible:contains("Create Tag")').first(),createButton=$('button:contains("Create Tag")',rootObject).first(),inputsKey=$('input[name="key"]',rootObject),inputsValue=$('input[name="value"]',rootObject),tags=$.parseJSON(prompt('JSON tag values')),tagsKeys=Object.keys(tags);if(tagsKeys.length>inputsKey.length){for(var i=0;i<tagsKeys.length-inputsKey.length;i++){createButton.click()}inputsKey=$('input[name="key"]',rootObject);inputsValue=$('input[name="value"]',rootObject)}inputsKey.each(function(i,inputKey){var inputValue=inputsValue[i],tagKey=tagsKeys[i],tagValue=tags[tagKey];$(inputKey).val(tagKey);$(inputValue).val(tagValue)})})(jQuery,console)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment