Skip to content

Instantly share code, notes, and snippets.

@sasha240100
Created March 13, 2020 11:54
Show Gist options
  • Save sasha240100/dafdad417eb0d1223b9f7d6413004826 to your computer and use it in GitHub Desktop.
Save sasha240100/dafdad417eb0d1223b9f7d6413004826 to your computer and use it in GitHub Desktop.
function traverse(data) {
return Array.from(data).map(item => {
const name = item.innerText.split('\n')[0].trim();
const skill = {
value: name.toLowerCase(),
label: name
};
if (item.children.length !== 0) {
skill.children = traverse(item.children[0].children);
}
return skill;
})
}
function copyToClipboard(text) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
function generateJsonFromSkillsList() {
const data = document.querySelector('#Placeholderdatamockups-skills').parentNode.parentElement.querySelector('ul');
const result = JSON.stringify(traverse(data.children));
copyToClipboard(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment