Skip to content

Instantly share code, notes, and snippets.

@illarionvk
Created September 30, 2014 09:01
Show Gist options
  • Save illarionvk/be3e1364da1721d9d8ce to your computer and use it in GitHub Desktop.
Save illarionvk/be3e1364da1721d9d8ce to your computer and use it in GitHub Desktop.
Automate adding numeric range to dropdown - Bold Apps Product Options app for Shopify
// Run the code in developer console, done best through Chrome's Javascript snippets
// First add LoDash
$('body').append('<script src="//cdn.jsdelivr.net/lodash/2.4.1/lodash.min.js"></script>');
// Add range of steps to Bold Apps Product Option dropdown
(function() {
var valueRange = _.range(-5, 5.25, 0.25);
function addNewValue(value) {
$('#option_name').val(value);
$(".add_new_option .btn[data-original-title='Add Option']").click();
}
_.forEach(valueRange, function(num, index) {
var escapedNum = (function() {
var numString = num + ""
if (num > 0) {
return '&plus;' + numString
} else {
return numString.replace('-', '&minus;')
}
})();
window.setTimeout(
addNewValue,
index * 200 + 500,
escapedNum
);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment