Created
September 15, 2018 14:00
-
-
Save drenther/246c90bf8f4ae1a414c025d73ca179ed to your computer and use it in GitHub Desktop.
A tiny script to simplify Amizone feedback
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
function rate(rating) { | |
const submit = document.querySelector(`input[type="submit"]`); | |
submit.removeAttribute('onclick'); | |
if (![0, 1, 2, 3, 4].includes(rating)) { | |
console.log("rate(0) for Strongly Agree, rate(1) for Agree, rate(2) for Neutral, rate(4) for Strongly Disagree"); | |
} else { | |
const inputs = [...document.querySelectorAll(`input[type="radio"]`)]; | |
const ratings = inputs.filter( x => x.id.endsWith(`Rating_${rating}`) ); | |
const questions = inputs.filter( x => x.id.includes(`Question`)); | |
const text = document.querySelector('textarea'); | |
ratings.forEach( x => { | |
x.checked = true; | |
x.parentElement.style = "background-color: rgb(185, 222, 138)"; | |
}); | |
if (rating >= 0 && rating <= 2) { | |
questions.filter( x => x.id.endsWith('0')).forEach( x => x.checked = true ); | |
} else { | |
questions.filter( x => x.id.endsWith('1')).forEach( x => x.checked = true ); | |
} | |
switch (rating) { | |
case 0: | |
text.value = 'Great'; | |
break; | |
case 1: | |
text.value = 'Good'; | |
break; | |
case 2: | |
text.value = 'Okay'; | |
break; | |
case 3: | |
text.value = 'Not so good'; | |
break; | |
case 4: | |
text.value = 'Bad'; | |
break; | |
} | |
} | |
submit.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment