- Visit the labels page you want to copy
- Open the Developer Console
- Paste this snippet and hit enter
const labels = [];
const list = [].slice.call(document.querySelectorAll(".js-label-link"));
list.forEach((element) => {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("title"),
color: element.getAttribute("style")
.replace("background-color:", "")
.replace(/color:.*/,"")
.trim()
// github wants hex code only without # or ;
.replace(/^#/, "")
.replace(/;$/, "")
.trim(),
})
});
console.log(JSON.stringify(labels, null, 2))
You should see an output for all of the labels listed.
Now you need to:
- Assign the output Array to a
const
nameslabels
(const labels = [...]); - Visit the new labels page where you want to import the labels
- Click the "New Label" button
- Open Developer Console
- Open the Developer Console
- Paste this snippet and hit enter
const name = document.getElementById('label-name-');
const description = document.getElementById('label-description-');
const color = document.getElementById('label-color-');
const submit = document.querySelector('.js-label-form .btn.btn-primary');
labels.forEach((label) => addNewLabel(label));
function addNewLabel (label) {
name.value = label.name;
description.value = label.description;
color.value = '#' + label.color;
submit.removeAttribute('disabled');
submit.click();
}