Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
students:value-calculator-quiz [2024/01/26 02:33] – steve.wang | students:value-calculator-quiz [2024/01/27 01:42] (current) – steve.wang | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Value calculator ====== | ||
+ | |||
< | < | ||
- | <script> | + | |
- | //helped by chatgpt | + | <meta name=" |
- | //maybe partially bardAI | + | <!-- Code made using Github Copilot and Google Bard --> |
- | function removeCrap (){ | + | <style> |
- | document.getElementsByTagName(' | + | /* cODE MAde using Github Copilot Google Bard */ |
- | document.getElementsByTagName(' | + | /* Changed background color from black to grey, change font color to light grey, change font from default to this.*/ |
+ | html, body { | ||
+ | color: white; | ||
+ | | ||
+ | height: 90%; | ||
+ | /* overflow: auto;*/ | ||
+ | background-color: | ||
+ | color: white; | ||
+ | | ||
+ | transition: opacity | ||
+ | font-family: | ||
} | } | ||
- | let pitchStuff = document.createElement(' | ||
- | pitchStuff.id = ' | ||
- | // Create a container div | ||
- | var sliderContainer = document.createElement(' | ||
- | sliderContainer.classList.add(' | ||
- | // Create min label | + | # |
- | var minLabel = document.createElement(' | + | |
- | minLabel.setAttribute(' | + | |
- | minLabel.textContent = ' | + | } |
- | minLabel.style.color = ' | + | |
- | // Create max label | + | #tBox{ |
- | var maxLabel = document.createElement(' | + | |
- | maxLabel.setAttribute(' | + | |
- | maxLabel.textContent = ' | + | |
- | maxLabel.style.color = 'white' | + | color: white; |
+ | background-color: | ||
+ | border-style: | ||
+ | border-width: | ||
+ | border-color: | ||
+ | } | ||
- | // Create a button with id ' | ||
- | var backButton = document.createElement(' | ||
- | backButton.id = ' | ||
- | backButton.textContent = ' | ||
- | backButton.style.fontSize = ' | ||
- | pitchStuff.appendChild(backButton); | ||
- | // Style the ' | + | #question { |
- | backButton.style.display = ' | + | |
+ | text-wrap: wrap; | ||
+ | width: 99%; | ||
+ | font-size: 400%; | ||
+ | } | ||
- | // Create a button with id ' | + | #timer{ |
- | var averageButton = document.createElement(' | + | |
- | averageButton.id = ' | + | |
- | averageButton.textContent = ' | + | |
- | averageButton.style.fontSize = ' | + | |
- | pitchStuff.appendChild(averageButton); | + | color: white; |
+ | font-size: | ||
+ | border-style:solid; | ||
+ | border-width: | ||
+ | border-color: | ||
+ | | ||
+ | | ||
+ | | ||
+ | /* | ||
+ | | ||
+ | See http://ie.microsoft.com/ | ||
+ | */ | ||
+ | | ||
+ | | ||
+ | } | ||
+ | /* Make text unselectable: | ||
- | // Style the ' | + | # |
- | averageButton.style.display = ' | + | |
+ | left: min(100px, 3%); | ||
+ | max-width: 94%; | ||
+ | font-size: 200%; | ||
+ | } | ||
- | // Create a button with id ' | + | /* Text wrap: https://developer.mozilla.org/ |
- | var hiButton = document.createElement(' | + | |
- | hiButton.id = ' | + | |
- | hiButton.textContent = 'Press to start Pitch Machine'; | + | |
- | hiButton.style.fontSize = ' | + | |
- | pitchStuff.appendChild(hiButton); | + | |
- | // Style the ' | + | .grid-container { |
- | hiButton.style.display | + | |
+ | grid-template-columns: | ||
+ | background-color: | ||
+ | vertical-align: | ||
+ | } | ||
- | // Create a button with id ' | + | .grid-item { |
- | var enterMButton = document.createElement(' | + | left: 0%; |
- | enterMButton.id = ' | + | background-color: |
- | pitchStuff.appendChild(enterMButton); | + | border: 1px solid grey; |
+ | font-size: 200%; | ||
+ | padding: 3%; | ||
+ | text-align: center; | ||
+ | -webkit-user-select: | ||
+ | -moz-user-select: | ||
+ | -ms-user-select: | ||
+ | user-select: | ||
+ | | ||
+ | vertical-align: | ||
+ | } | ||
+ | /* CSS animations: https:// | ||
+ | /* https:// | ||
- | // Style the ' | + | .grid-item: |
- | enterMButton.style.display = ' | + | cursor: pointer; |
+ | } | ||
- | // Create a button with id ' | + | # |
- | var enterFButton = document.createElement(' | + | |
- | enterFButton.id = ' | + | |
- | pitchStuff.appendChild(enterFButton); | + | |
+ | width: 10%; | ||
+ | height: 20%; | ||
+ | position: absolute; | ||
+ | top: -100%; | ||
+ | left: 25%; | ||
+ | font-size: 550%; | ||
+ | display: none; | ||
+ | transition: width 0.5s, top 1s; | ||
+ | overflow-wrap: | ||
+ | overflow: scroll; | ||
+ | } | ||
- | // Style the ' | + | @media (orientation: |
- | enterFButton.style.display = ' | + | .grid-item{ |
+ | font-size: 300%; | ||
+ | padding: 2%; | ||
+ | } | ||
+ | #timer{ | ||
+ | width: auto; | ||
+ | font-size: 300%; | ||
+ | } | ||
+ | | ||
+ | width: 100% | ||
+ | } | ||
+ | #tBox{ | ||
+ | font-size: 350%; | ||
+ | width: 85%; | ||
+ | } | ||
+ | # | ||
+ | font-size: 200%; | ||
+ | text-align: center; | ||
+ | justify-content: | ||
+ | align-items: | ||
+ | vertical-align: | ||
+ | } | ||
+ | # | ||
+ | font-size: 200%; | ||
+ | text-align: center; | ||
+ | align-items: | ||
+ | justify-content: | ||
+ | } | ||
+ | # | ||
+ | font-size: 230%; | ||
+ | } | ||
+ | # | ||
+ | font-size: 130% | ||
+ | } | ||
+ | # | ||
+ | font-size: 110%; | ||
+ | } | ||
+ | # | ||
+ | font-size: 300%; | ||
+ | width: 100%; | ||
+ | left: 0px | ||
+ | } | ||
+ | } | ||
- | // Create range input | ||
- | var rangeInput = document.createElement(' | ||
- | rangeInput.setAttribute(' | ||
- | rangeInput.setAttribute(' | ||
- | rangeInput.setAttribute(' | ||
- | rangeInput.setAttribute(' | ||
- | rangeInput.classList.add(' | ||
- | rangeInput.setAttribute(' | ||
- | // Create slider value display | + | # |
- | var sliderValue = document.createElement(' | + | |
- | sliderValue.setAttribute(' | + | |
- | sliderValue.textContent = ' | + | } |
- | sliderValue.style.color = ' | + | |
- | sliderValue.style.fontSize = ' | + | |
- | // Append elements to the container div | + | # |
- | sliderContainer.appendChild(minLabel); | + | |
- | sliderContainer.appendChild(rangeInput); | + | |
- | sliderContainer.appendChild(maxLabel); | + | text-wrap: wrap; |
+ | color: #e9e9e9; | ||
+ | background-color: | ||
+ | border-color: | ||
+ | transition: top 1s; | ||
+ | padding-left: | ||
+ | padding-right: | ||
+ | padding-top: | ||
+ | | ||
+ | font-size: 160%; | ||
+ | -webkit-user-select: | ||
+ | -moz-user-select: | ||
+ | -ms-user-select: | ||
+ | user-select: | ||
+ | top: 2%; | ||
+ | right: 3%; | ||
+ | z-Index: 1; | ||
+ | } | ||
+ | /* https:// | ||
- | // Append container | + | # |
- | pitchStuff.appendChild(sliderContainer); | + | cursor: pointer; |
- | pitchStuff.appendChild(sliderValue); | + | opacity: 0.9; |
+ | } | ||
+ | </style> | ||
+ | <div id=' | ||
+ | <body> | ||
+ | < | ||
+ | <h4 id = ' | ||
+ | <input id=' | ||
+ | < | ||
+ | <!-- generated by BardAI --> | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div class=" | ||
+ | <div id=' | ||
+ | <div class=" | ||
+ | </ | ||
+ | <!-- Number pad from w3 schools : https://www.w3schools.com/ | ||
+ | <!-- https://www.w3schools.com/ | ||
+ | < | ||
+ | // -------------------------------------------------------------------------- | ||
+ | // -- value-calculator.js | ||
+ | // -------------------------------------------------------------------------- | ||
+ | // Code made using Github Copilot and Google Bard | ||
+ | // Translation helped by Google Translate | ||
- | document.documentElement.appendChild(pitchStuff) | + | document.body.style.opacity = 0 |
+ | //let referrer = ' | ||
+ | //This line is written by Yiler | ||
+ | let referrerFrom = " | ||
+ | let referrerTo = " | ||
+ | // let resultsPageLink = ' | ||
+ | let resultsPageLink = ' | ||
- | // Find the HTML element with the id " | + | let mode = 'doku' |
- | var mySlider | + | |
- | // Create a < | + | let language |
- | var styleElement | + | |
- | // Define CSS rules for the .slider class | + | let conditions= { |
- | var cssText | + | P: 0.23, //Max 15 |
- | ' | + | V: 0.17, //Max 5 |
- | ' | + | M: 0.12, //Max 5 |
- | ' | + | S: 0.12, //Max 15 |
- | ' | + | R: 0.10, //Max 5 |
- | ' | + | I: 0.12, //Max 5 |
- | ' | + | B: 0.06, //Max 5 |
- | ' | + | E: 0.05, //Max 5 |
- | ' | + | A: 0.04, //Max 5 |
- | ' | + | } |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | '.slider:: | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | '.slider:: | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | // Set the CSS rules as text content of the < | + | let total = { |
- | styleElement.textContent | + | P: 15, |
+ | V: 5, | ||
+ | M: 5, | ||
+ | S: 15, | ||
+ | R: 5, | ||
+ | I: 5, | ||
+ | B: 5, | ||
+ | E: 5, | ||
+ | A: 5, | ||
+ | } | ||
- | // Append the < | + | let minumumTotal = { |
- | document.documentElement.appendChild(styleElement); | + | P: 0, |
+ | V: 0, | ||
+ | M: 0, | ||
+ | S: 0, | ||
+ | R: 0, | ||
+ | I: 0, | ||
+ | B: 0, | ||
+ | E: 0, | ||
+ | A: 0, | ||
+ | } | ||
+ | //Each answer is based on 0 to 5 except P is 0 - 5, | ||
- | // Find the HTML element with the id " | + | let compButton |
- | var min = document.getElementById(' | + | |
- | // Apply styles to the " | + | function valueCalc (options){ |
- | min.style.top | + | let total = 0 |
- | min.style.left = ' | + | |
- | min.style.position | + | if (options[x] |
- | min.style.fontSize | + | total += conditions[x] |
+ | } | ||
+ | else { | ||
+ | console.log('caculating' | ||
+ | total += conditions[x] * options[x] | ||
+ | } | ||
+ | }) | ||
+ | return total | ||
+ | } | ||
- | // Find the HTML element with the id "max" | + | let currentName= '' |
- | var max = document.getElementById('max'); | + | let questions |
+ | P: {qE: 'How many positive personal qualities of NAME can you list in 50 seconds?', | ||
+ | V: {qE:' | ||
+ | M: {qE:' | ||
+ | S: {qE:' | ||
+ | R: {qE:' | ||
+ | I: {qE:"How positive is NAME ’s public image? 0- very bad, 5- very good", qC: ' NAME 的公衆形象如何? 0- 形象非常不好, 5- 形象非常好', | ||
+ | | ||
+ | E: {qE:' | ||
+ | A: {qE:" | ||
+ | } | ||
+ | // | ||
- | // Apply styles to the " | + | function changeNotificationLanguage (){ |
- | max.style.left = '40%'; | + | let notificationBoxContent = notificationBox.innerText.split(' |
- | max.style.top = '90%'; | + | if (language === 'English' |
- | max.style.position | + | |
- | max.style.fontSize | + | } |
+ | else if (language === 'English'){ | ||
+ | | ||
+ | } | ||
+ | else if (notificationBox.innerText[notificationBox.innerText.length - 1] === '字'){ | ||
+ | | ||
+ | } | ||
+ | else { | ||
+ | notificationBox.innerText | ||
+ | } | ||
+ | } | ||
- | // Find the HTML element with the id " | + | function changeNamePageLanguage (){ |
- | var enterM | + | if (language |
+ | | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | else { | ||
+ | document.getElementById(' | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | } | ||
- | // Apply styles to the " | + | function changeLanguage (){ |
- | enterM.style.position | + | let q = Object.values(questions)[qIndex] |
- | enterM.style.right = '0%'; | + | nextQAnimation() |
- | enterM.style.fontSize | + | if (document.getElementById(' |
+ | | ||
+ | changeInstructions(q.type) | ||
+ | } | ||
+ | else{ | ||
+ | changeNamePageLanguage() | ||
+ | } | ||
+ | if (language === 'Chinese'){ | ||
+ | | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | else { | ||
+ | document.getElementById(' | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | if (notificationBox.style.display === 'block'){ | ||
+ | changeNotificationLanguage() | ||
+ | } | ||
+ | } | ||
- | // Find the HTML element with the id " | + | function updateQ (x){ |
- | var enterF | + | let q = x.qE |
+ | if (language === 'Chinese'){ | ||
+ | q = x.qC | ||
+ | } | ||
+ | let currentQ = q.split(' | ||
+ | console.log(' | ||
+ | currentQ[q.split(' | ||
+ | return currentQ.join(' | ||
+ | } | ||
- | // Apply styles to the " | + | function changeInstructions(type){ |
- | enterF.style.position | + | if (language === ' |
- | enterF.style.right = '0%'; | + | |
- | enterF.style.top | + | } |
- | enterF.style.fontSize | + | else if (language === ' |
- | enterF.style.color = 'pink'; | + | document.getElementById(' |
+ | } | ||
+ | else if (language === 'Chinese' | ||
+ | | ||
+ | } | ||
+ | else { | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | } | ||
+ | //google translate used for some translation. | ||
- | // Find the HTML element with the id " | + | function changeQ (x){ |
- | var back = document.getElementById(' | + | |
+ | changeInstructions(x.type) | ||
+ | if (x.type === ' | ||
+ | | ||
+ | stopCountdown() | ||
+ | timerState = ' | ||
+ | countdownEnded() | ||
+ | setTimeout(() => { | ||
+ | startCountdown(50) | ||
+ | let currentQIndex = qIndex | ||
+ | setTimeout(() => { | ||
+ | if (qIndex == currentQIndex && qIndex !== undefined){ | ||
+ | alert(' | ||
+ | document.getElementById(' | ||
+ | nextQ() | ||
+ | } | ||
+ | }, 49990) | ||
+ | }, 1000) | ||
+ | } | ||
+ | else { | ||
+ | document.getElementById(' | ||
+ | stopCountdown() | ||
+ | timerState = ' | ||
+ | countdownEnded() | ||
+ | setTimeout(() => { | ||
+ | startCountdown(35) | ||
+ | let currentQIndex = qIndex | ||
+ | setTimeout(() => { | ||
+ | if (qIndex == currentQIndex && qIndex !== undefined){ | ||
+ | alert(' | ||
+ | document.getElementById(' | ||
+ | nextQ() | ||
+ | } | ||
+ | }, 34990) | ||
+ | }, 1000) | ||
+ | } | ||
+ | } | ||
- | // Apply styles to the " | + | function recordListAnswer (n){ |
- | back.style.position = ' | + | if (n > 15){ |
- | back.style.left = ' | + | |
- | back.style.top = ' | + | } |
+ | else if (n < 0){ | ||
+ | return 0 | ||
+ | } | ||
+ | return n | ||
+ | } | ||
- | // Find the HTML element with the id " | + | function record0To5Answer (n){ |
- | var average = document.getElementById(' | + | |
+ | return 0 | ||
+ | } | ||
+ | else if (n > 5){ | ||
+ | return 5 | ||
+ | } | ||
+ | return n | ||
+ | } | ||
- | // Apply styles to the " | + | function recordAnswers (){ |
- | average.style.position | + | let ans = document.getElementById(' |
- | average.style.left = '0px'; | + | let instructions |
- | average.style.top = '30%'; | + | if (instructions === ' |
+ | | ||
+ | } | ||
+ | else { | ||
+ | answeredTotal[Object.keys(conditions)[qIndex]] | ||
+ | } | ||
+ | document.getElementById('tBox').value = '' | ||
+ | } | ||
- | // -------------------------------------------------------------------------- | + | //Timer: |
- | // -- test.js | + | |
- | // -------------------------------------------------------------------------- | + | |
- | // GAIN NOT WORKING PROPERLY | + | |
- | function | + | function |
- | const blob = new Blob([content], { type: ' | + | let roundedNumber=number.toFixed(decimalPlaces); |
+ | return JSON.parse(roundedNumber)} | ||
- | const link = document.createElement('a'); | + | let timeLeft = 0 |
- | link.href = window.URL.createObjectURL(blob); | + | let timerState |
- | link.download = filename; | + | |
- | // Append the link to the document | + | function clockFormat (){ |
- | | + | let minutes=JSON.stringify(Math.floor(timeLeft/60)) |
+ | let seconds=timeLeft%60 | ||
+ | if (minutes==' | ||
+ | minutes=' | ||
+ | } | ||
+ | if (seconds< | ||
+ | seconds=' | ||
+ | } | ||
+ | return minutes+':' | ||
+ | } | ||
- | // Trigger a click on the link to initiate the download | + | function startCountdown (totalTime){ |
- | | + | |
+ | timerState=' | ||
+ | timerCountdown() | ||
+ | } | ||
- | // Remove the link from the document | + | function timerCountdown (){ |
- | document.body.removeChild(link); | + | if (timeLeft==0){ |
+ | timerState=' | ||
+ | countdownEnded() | ||
+ | } | ||
+ | if (timerState==' | ||
+ | timeLeft-=1 | ||
+ | | ||
+ | checkIfTimerRunningOut() | ||
+ | setTimeout(()=> | ||
+ | timerCountdown() | ||
+ | },1000) | ||
+ | } | ||
+ | else{ | ||
+ | document.getElementById(' | ||
+ | } | ||
} | } | ||
- | // Example usage | + | function checkIfTimerRunningOut (){ |
+ | if (timeLeft< | ||
+ | new Audio(' | ||
+ | } | ||
+ | if (timeLeft==0){ | ||
+ | new Audio(' | ||
+ | } | ||
+ | } | ||
- | let averageN = 8105.972222222223 | ||
- | let data = [] | + | function stopCountdown (){ |
+ | timerState=' | ||
+ | document.getElementById(' | ||
+ | } | ||
- | let dataString | + | function countdownEnded (){ |
+ | if (timerState!='done'){ | ||
+ | return true | ||
+ | } | ||
+ | if (document.getElementById(' | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | else{ | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | setTimeout(()=> | ||
+ | countdownEnded () | ||
+ | },1000) | ||
+ | } | ||
- | function | + | |
- | | + | function |
- | | + | |
- | oscillator.frequency.setValueAtTime(1000, | + | timerCountdown() |
- | return oscillator | + | |
} | } | ||
- | /* | + | function pauseCountdown |
- | let audioContext = new (window.AudioContext || window.webkitAudioContext)(); | + | |
- | let oscillator | + | } |
- | oscillator.start(); | + | |
- | */ | + | |
- | let audioContext; | + | |
- | let oscillator; | + | |
- | // document.addEventListener('click', function() { | + | function blinkCompButton (){ |
- | // if (audioContext | + | let compButton = document.getElementById('compareResults') |
- | // | + | for (let i = 0; i < 6; i++) { |
+ | let a = i - 1 | ||
+ | | ||
+ | a = 0 | ||
+ | } | ||
+ | setTimeout(() | ||
+ | compButton.style.color = ' | ||
+ | }, 1000 * i + 500) | ||
+ | } | ||
+ | for (let i = 0; i < 5; i++) { | ||
+ | | ||
+ | compButton.style.color = 'grey' | ||
+ | }, 1000 * i) | ||
+ | } | ||
+ | } | ||
- | // audioContext | + | function removeAllExceptSeeResults (){ |
- | // oscillator | + | nextQAnimation() |
- | // oscillator.start(); | + | let bodyChildren = document.body.childNodes |
- | // | + | if (mode === ' |
+ | bodyChildren = document.getElementsByClassName(' | ||
+ | } | ||
+ | for (let i = 0; i < bodyChildren.length; | ||
+ | if (bodyChildren[i].id !== ' | ||
+ | bodyChildren[i].remove() | ||
+ | } | ||
+ | } | ||
+ | let compButton = document.getElementById(' | ||
+ | compButton.style.width = ' | ||
+ | compButton.style.height = ' | ||
+ | compButton.style.position = ' | ||
+ | compButton.style.display = ' | ||
+ | if (mode === ' | ||
+ | compButton.style.top = ' | ||
+ | } | ||
+ | else { | ||
+ | compButton.style.top = ' | ||
+ | } | ||
+ | compButton.style.left = ' | ||
+ | blinkCompButton() | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | function checkIfCompareResults (){ | ||
+ | if (answers.length === 2){ | ||
+ | let compButton = document.getElementById(' | ||
+ | compButton.href = createLinkWithData(resultsPageLink) | ||
+ | compButton.style.position = ' | ||
+ | compButton.style.display = ' | ||
+ | // compButton.style.top | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | // } | ||
+ | // else { | ||
+ | // | ||
+ | // } | ||
+ | // | ||
+ | // }, 1000) | ||
+ | // setTimeout(() => { | ||
+ | // | ||
+ | // compButton.style.top = ' | ||
+ | // }, 2002) | ||
+ | removeAllExceptSeeResults() | ||
+ | } | ||
+ | else if (answers.length > 2){ | ||
+ | let compButton = document.getElementById(' | ||
+ | compButton.style.display = ' | ||
+ | compButton.href = createLinkWithData(resultsPageLink) | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | let qIndex = 0 | ||
+ | let answeredTotal = {} | ||
+ | let lastName = '' | ||
+ | let virtualKeyboardAPI = navigator.virtualKeyboard | ||
+ | let answers = [] | ||
+ | function nextQ (){ | ||
+ | // if (currentName === '' | ||
+ | // alert(' | ||
+ | // | ||
+ | // } | ||
+ | if (isNaN(document.getElementById(' | ||
+ | notifyUser(' | ||
+ | return false | ||
+ | } | ||
+ | else if (document.getElementById(' | ||
+ | notifyUser(' | ||
+ | return false | ||
+ | } | ||
+ | if (qIndex === Object.keys(questions).length - 1){ | ||
+ | // showResults() | ||
+ | nextQAnimation() | ||
+ | console.log(valueCalc(answeredTotal)) | ||
+ | answers.push({name: | ||
+ | stopQuiz() | ||
+ | checkIfCompareResults() | ||
+ | return false | ||
+ | } | ||
+ | deactivateGridEvents() | ||
+ | recordAnswers() | ||
+ | qIndex++ | ||
+ | | ||
+ | nextQAnimation() | ||
+ | setTimeout(() => { | ||
+ | changeQ(Object.values(questions)[qIndex]) | ||
+ | }, 100) | ||
+ | setTimeout(() => { | ||
+ | activateGridEvents() | ||
+ | }, 500) | ||
+ | } | ||
+ | |||
+ | // changeQ(questions.P) | ||
+ | |||
+ | function resetQuiz (){ | ||
+ | qIndex = 0 | ||
+ | answeredTotal = {} | ||
+ | } | ||
+ | |||
+ | let notificationBox = document.getElementById(' | ||
+ | |||
+ | notificationBox.onpointerup = hideNotification | ||
+ | |||
+ | function hideNotification (){ | ||
+ | notificationBox.style.top = '-100%' | ||
+ | setTimeout(() => { | ||
+ | notificationBox.style.display = ' | ||
+ | notificationBox.style.transition = ' | ||
+ | notificationBox.style.top = ' | ||
+ | notificationBox.style.right = ' | ||
+ | notificationBox.style.transition = '' | ||
+ | }, 1000) | ||
+ | } | ||
+ | |||
+ | function showNotification () { | ||
+ | // | ||
+ | notificationBox.style.display = ' | ||
+ | } | ||
+ | |||
+ | function notifyUser (message){ | ||
+ | notificationBox.innerText = message | ||
+ | showNotification() | ||
+ | setTimeout(() => { | ||
+ | if (notificationBox.style.display === ' | ||
+ | hideNotification() | ||
+ | } | ||
+ | }, 8000) | ||
+ | } | ||
+ | |||
+ | function notifyUserInfoSaved (){ | ||
+ | if (language === ' | ||
+ | notifyUser(' | ||
+ | } | ||
+ | else { | ||
+ | notifyUser(answers[answers.length - 1].name.toUpperCase() + ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function notifyUserToCompareResults (){ | ||
+ | if (language === ' | ||
+ | notifyUser(' | ||
+ | } | ||
+ | else { | ||
+ | notifyUser(answers[answers.length - 1].name.toUpperCase() + ' | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function stopQuiz (){ | ||
+ | qIndex = undefined | ||
+ | // | ||
+ | // | ||
+ | stopCountdown() | ||
+ | timerState = ' | ||
+ | countdownEnded() | ||
+ | lastName = currentName | ||
+ | currentName = '' | ||
+ | newQuizSubject() | ||
+ | setTimeout(() => { | ||
+ | if (answers.length === 1){ | ||
+ | notifyUserInfoSaved() | ||
+ | } | ||
+ | else { | ||
+ | notifyUserToCompareResults() | ||
+ | } | ||
+ | }, 200) | ||
+ | // | ||
+ | // | ||
+ | } | ||
+ | |||
+ | // answeredTotal = { | ||
+ | // P: 5, | ||
+ | // V: 5, | ||
+ | // M: 5, | ||
+ | // S: 15, | ||
+ | // R: 5, | ||
+ | // I: 5, | ||
+ | // B: 5, | ||
+ | // E: 5, | ||
+ | // A: 5, | ||
// } | // } | ||
- | // }) | + | // //Each answer is based on 0 to 5 except P is 0 - 5, |
+ | //A function that creates a ruler like thing that shows the value of the person. | ||
+ | function showResults () { | ||
+ | let results = document.getElementById(' | ||
+ | // | ||
+ | // let results = valueCalc(answeredTotal) | ||
+ | let ruler = document.createElement(' | ||
+ | ruler.style.width = ' | ||
+ | ruler.style.height = ' | ||
+ | ruler.style.border = '10px solid black' | ||
+ | ruler.style.position = ' | ||
+ | //center ruler horizontal in page: | ||
+ | ruler.style.left = ' | ||
+ | ruler.style.top = ' | ||
+ | //show text above ruler that says max is 8.5 | ||
+ | let max = document.createElement(' | ||
+ | max.innerText = 'Max is 8.4' | ||
+ | max.style.position = ' | ||
+ | max.style.top = ' | ||
+ | max.style.left = ' | ||
+ | max.style.fontSize = ' | ||
+ | max.style.fontWeight = ' | ||
+ | max.style.left = ' | ||
+ | max.style.width = ' | ||
+ | //show text below ruler that says min is 0 | ||
+ | let min = document.createElement(' | ||
+ | min.innerText = 'Min is 0' | ||
+ | min.style.position = ' | ||
+ | min.style.top = ' | ||
+ | min.style.fontSize = ' | ||
+ | min.style.fontWeight = ' | ||
+ | min.style.left = ' | ||
+ | min.style.width = ' | ||
+ | let value = valueCalc(answeredTotal) | ||
+ | let rect = document.createElement(' | ||
+ | rect.style.width = ' | ||
+ | rect.style.height = ' | ||
+ | rect.style.backgroundColor = ' | ||
+ | rect.style.position = ' | ||
+ | rect.style.top = 80 - (value/8.5 * 100) + ' | ||
+ | rect.style.left = ' | ||
+ | rect.innerText = roundOff(value, | ||
+ | rect.style.zIndex = ' | ||
+ | rect.style.fontWeight = ' | ||
+ | rect.style.textAlign = ' | ||
+ | // | ||
+ | if (JSON.parse(rect.style.top.slice(0, | ||
+ | rect.style.top = ' | ||
+ | } | ||
+ | else if (JSON.parse(rect.style.top.slice(0, | ||
+ | rect.style.top = ' | ||
+ | } | ||
+ | results.appendChild(max) | ||
+ | results.appendChild(min) | ||
+ | results.appendChild(rect) | ||
+ | results.appendChild(ruler) | ||
- | document.getElementById(" | + | } |
- | // | + | |
- | // | + | |
- | // | + | |
- | const sliderValue = document.getElementById(" | + | |
- | console.log(' | + | |
- | document.getElementById(" | + | |
- | oscillator.frequency.setValueAtTime(sliderValue, | + | |
- | }); | + | |
- | document.getElementById(' | + | |
- | if (audioContext | + | |
- | document.documentElement.style.backgroundColor | + | // Show text on the top that shows max is 8.5 and min is 0 show that text below. Put all that in the results div. |
- | | + | |
- | | + | // showResults() |
- | | + | |
- | | + | // make is so when tBox is focused and enter is clicked, nexQ fuction will be called: |
+ | |||
+ | function preventNonNumericalInputs (e){ | ||
+ | if (e.keyCode < 48 || e.keyCode > 57) { | ||
+ | | ||
+ | return false | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function startQuiz (e){ | ||
+ | currentName = document.getElementById(' | ||
+ | if (currentName === '' | ||
+ | alert(' | ||
+ | return false | ||
+ | | ||
+ | else if (currentName | ||
+ | | ||
+ | return false | ||
+ | } | ||
+ | console.log(' | ||
+ | | ||
+ | document.getElementById(' | ||
+ | | ||
+ | document.getElementById(' | ||
+ | nextQAnimation() | ||
+ | setTimeout(() => { | ||
+ | resetQuiz() | ||
+ | changeQ(questions.P) | ||
+ | }) | ||
+ | document.getElementById(' | ||
+ | | ||
+ | nextQ() | ||
+ | | ||
+ | let tBox = document.getElementById(' | ||
+ | | ||
+ | console.log(' | ||
+ | return false | ||
+ | } | ||
+ | setTimeout(() => { | ||
+ | console.log(tBox.value, | ||
+ | if (JSON.parse(tBox.value) > JSON.parse(tBox.max)){ | ||
+ | tBox.value = tBox.max | ||
+ | } | ||
+ | else if (JSON.parse(tBox.value) < JSON.parse(tBox.min)){ | ||
+ | tBox.value = tBox.min | ||
+ | } | ||
+ | }, 100) | ||
} | } | ||
} | } | ||
- | //YOOO | + | function hideTboxVirtualKeyboard (){ |
+ | tBox.readOnly = true | ||
+ | tBox.disabled = true | ||
+ | tBox.blur() | ||
+ | tBox.readOnly = false | ||
+ | tBox.disabled = false | ||
+ | } | ||
+ | // From: https:// | ||
- | document.getElementById('enterM').innerText | + | function nextQAnimation (){ |
- | document.getElementById(' | + | hideTboxVirtualKeyboard() |
+ | scroll(0, 0) | ||
+ | | ||
+ | setTimeout(() => { | ||
+ | document.body.style.opacity | ||
+ | }, 200) | ||
+ | } | ||
- | document.getElementById(' | + | function newQuizSubject (){ |
- | | + | changeNamePageLanguage() |
- | | + | |
- | dataString += 'M,' | + | |
+ | | ||
+ | | ||
+ | startQuiz(e) | ||
+ | } | ||
+ | } | ||
} | } | ||
- | document.getElementById(' | + | newQuizSubject() |
- | | + | |
- | | + | function |
- | dataString += 'F,' | + | |
+ | | ||
+ | startQuiz(e) | ||
+ | } | ||
+ | else{ | ||
+ | nextQ() | ||
+ | } | ||
} | } | ||
- | document.getElementById(' | + | |
- | | + | // function getValue (){ |
+ | // | ||
+ | // } | ||
+ | // let tBox = document.getElementById(' | ||
+ | // document.getElementById(' | ||
+ | // | ||
+ | // if (isNaN(event.key) === true) { | ||
+ | // | ||
+ | // tBox.value = getValue().slice(0, -1 ) | ||
+ | // } | ||
+ | // }) | ||
+ | // }); | ||
+ | |||
+ | let gridItems = document.getElementsByClassName(' | ||
+ | |||
+ | function activateGridEvents (){ | ||
+ | if (gridItems[0].onpointerup !== null){ | ||
+ | return false | ||
+ | } | ||
+ | for (let i = 0; i < gridItems.length; | ||
+ | let x = gridItems[i] | ||
+ | if (x.id === ' | ||
+ | x.onpointerup = function (e) { | ||
+ | console.log(' | ||
+ | let tBox = document.getElementById(' | ||
+ | tBox.value = tBox.value.slice(0, | ||
+ | // | ||
+ | keyClickedAnimation(e.target) | ||
+ | } | ||
+ | } | ||
+ | else if (x.id !== ' | ||
+ | x.onpointerup = function (e) { | ||
+ | let value = e.target.innerText | ||
+ | console.log(' | ||
+ | document.getElementById(' | ||
+ | // | ||
+ | keyClickedAnimation(e.target) | ||
+ | setTimeout(() => { | ||
+ | console.log(tBox.value, | ||
+ | if (JSON.parse(tBox.value) > JSON.parse(tBox.max)){ | ||
+ | tBox.value = tBox.max | ||
+ | } | ||
+ | else if (JSON.parse(tBox.value) < JSON.parse(tBox.min)){ | ||
+ | tBox.value = tBox.min | ||
+ | } | ||
+ | }, 100) | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | document.getElementById(' | ||
} | } | ||
- | document.getElementById(' | + | activateGridEvents() |
- | if (audioContext | + | |
- | | + | function |
- | | + | if (gridItems[0].onpointerup |
- | | + | |
- | | + | } |
+ | for (let i = 0; i < gridItems.length; i++) { | ||
+ | | ||
+ | | ||
} | } | ||
} | } | ||
- | document.getElementById(' | ||
- | // Function to prevent scrolling | + | function |
- | function | + | |
- | | + | setTimeout(() => { |
+ | // | ||
+ | e.style.color = ' | ||
+ | }, 100) | ||
} | } | ||
- | // Add event listener to the window object | + | document.getElementById(' |
- | window.addEventListener(' | + | console.log(e.key) |
+ | if (isNaN(e.key) === false){ | ||
+ | keyClickedAnimation(gridItems[JSON.parse(e.key) - 1]) | ||
+ | } | ||
+ | else if(e.key === ' | ||
+ | keyClickedAnimation(gridItems[10]) | ||
+ | } | ||
+ | else if (e.key === ' | ||
+ | keyClickedAnimation(gridItems[11]) | ||
+ | } | ||
+ | }) | ||
- | mySlider.style.top = '50%' | + | function getInformationFromLink (baseLink){ |
- | mySlider.style.left = '-25%' | + | let fullLink = window.location.href |
- | mySlider.style.position | + | let info; |
- | removeCrap() | + | if (baseLink !== undefined){ |
- | //slider code from: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_rangeslider | + | fullLink.slice(baseLink.length).split('&' |
- | </ | + | } |
+ | else { | ||
+ | info = fullLink.split('&' | ||
+ | } | ||
+ | let data = {} | ||
+ | data[info[0]] = info[1] | ||
+ | data[info[2]] = info[3] | ||
+ | return data | ||
+ | } | ||
+ | //Idea for using & character for passing information inspired by bardAI | ||
+ | |||
+ | function createLinkWithData (link){ | ||
+ | let outputLink = link | ||
+ | answers.forEach(x => { | ||
+ | outputLink += '&' | ||
+ | }) | ||
+ | // | ||
+ | return outputLink | ||
+ | } | ||
+ | |||
+ | function configureStylingForDokuWiki (){ | ||
+ | document.getElementsByClassName(' | ||
+ | | ||
+ | document.getElementsByClassName(' | ||
+ | | ||
+ | | ||
+ | let homeButton = document.getElementsByClassName(' | ||
+ | //Remove navbar: | ||
+ | document.getElementsByClassName(' | ||
+ | setTimeout(() => { | ||
+ | document.getElementById(' | ||
+ | document.getElementsByClassName(' | ||
+ | | ||
+ | | ||
+ | }, 50) | ||
+ | } | ||
+ | function checkReferrer (){ | ||
+ | if (document.referrer !== referrerFrom){ | ||
+ | removeAllExceptSeeResults() | ||
+ | document.getElementById(' | ||
+ | if (language === ' | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | else { | ||
+ | document.getElementById(' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | window.addEventListener(' | ||
+ | if (mode === ' | ||
+ | let copy = document.getElementsByClassName(' | ||
+ | let navbar = document.getElementsByClassName(" | ||
+ | let newBody = document.createElement(' | ||
+ | newBody.appendChild(copy) | ||
+ | newBody.appendChild(navbar) | ||
+ | document.body.remove() | ||
+ | document.documentElement.appendChild(newBody) | ||
+ | copy.style.top = ' | ||
+ | document.documentElement.style.boxSizing = ' | ||
+ | document.body.style.marginTop = ' | ||
+ | // | ||
+ | checkReferrer() | ||
+ | } | ||
+ | nextQAnimation() | ||
+ | | ||
+ | }) | ||
+ | |||
+ | value_calculator.style.color = ' | ||
+ | question.style.color = ' | ||
+ | instructions.style.color = ' | ||
+ | | ||
+ | < | ||
+ | <div id=' | ||
+ | <button id=' | ||
+ | </body> | ||
</ | </ | ||
+ | |||
+ | |||