Last active
October 17, 2017 19:17
-
-
Save Hum4n01d/faf38b0bcef6ed86e648f2e27bda13b5 to your computer and use it in GitHub Desktop.
PLP Hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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