Skip to content

Instantly share code, notes, and snippets.

@Hum4n01d
Last active October 17, 2017 19:17
Show Gist options
  • Save Hum4n01d/faf38b0bcef6ed86e648f2e27bda13b5 to your computer and use it in GitHub Desktop.
Save Hum4n01d/faf38b0bcef6ed86e648f2e27bda13b5 to your computer and use it in GitHub Desktop.
PLP Hack
const options = {
allGreen: {
className: 'success',
iconName: 'check',
classNameToRemove: 'danger'
},
allRed: {
className: 'danger',
iconName: 'clear',
classNameToRemove: 'success'
}
};
const mode = options.allGreen;
// Get all PFAS and projects
const pfas = document.querySelectorAll('.courserow-list-item-content');
// Get the icons of all completed PFAs and projects
const alreadyDoneIcons = document.querySelectorAll('i[icon="check"],i[icon="clear"]');
// Remove any existing icons from the PFA/project
alreadyDoneIcons.forEach(icon => {
const pfaLink = icon.parentNode;
// Remove icon
pfaLink.removeChild(icon);
// Remove success class
pfaLink.classList.remove(mode.classNameToRemove);
// Remove success class from parent (projects only)
pfaLink.parentNode.classList.remove(mode.classNameToRemove)
});
pfas.forEach(pfa => {
const pfaLink = pfa.childNodes[0];
// Give all PFAs the desired class
pfa.classList.add(mode.className);
// Add PFA's link the desired class
pfaLink.classList.add(mode.className);
// Create a new icon
const icon = document.createElement('i');
icon.setAttribute('icon', mode.iconName);
icon.innerText = mode.iconName;
icon.className = 'material-icons material-icons-default';
// Add the new icon to the PFA link before the title
pfaLink.insertBefore(icon, pfaLink.firstChild);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment