Last active
August 29, 2015 14:16
-
-
Save RickyCook/b428f7f72945d21d5cf9 to your computer and use it in GitHub Desktop.
Fill AWS tags based on a JSON hash, obtained from user prompt
This file contains hidden or 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
(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) |
This file contains hidden or 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
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