Skip to content

Instantly share code, notes, and snippets.

@danactive
Last active August 21, 2018 04:21
Show Gist options
  • Save danactive/9761569d5aa6d3fd0cc1e5f441fca4e7 to your computer and use it in GitHub Desktop.
Save danactive/9761569d5aa6d3fd0cc1e5f441fca4e7 to your computer and use it in GitHub Desktop.
Paste into browser developer console to reveal dropdown / pulldown menu labels and values
(() => {
const result = {};
const parseDropdownName = name => {
if (name.includes('$')) {
const lastItem = name.split('$').slice(-1)[0];
if (lastItem.startsWith('ddl')) return lastItem.substring(3);
return lastItem;
}
return name;
}
const makeFormatter = items => format => items.map(format).join('\n')
const getDropdownContent = dd => {
const items = Array.from(dd.querySelectorAll('option'));
const format = makeFormatter(items);
const name = parseDropdownName(dd.name);
if (name === 'Language') return;
const labels = format(item => item.innerHTML);
const values = format(item => item.value);
const valuesWithPercent = format(item => `%${item.value}`);
result[name] = {
labels,
values,
valuesWithPercent,
};
};
Array.from(document.querySelectorAll('select')).forEach(getDropdownContent);
return result;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment