| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  | let gameName = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  | window.addEventListener('load', () => { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   gameName = document.getElementById('player-options').getAttribute('data-game'); | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Update game name on page
 | 
					
						
							| 
									
										
										
										
											2021-11-03 09:33:47 +01:00
										 |  |  |   document.getElementById('game-name').innerText = gameName; | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   fetchOptionData().then((results) => { | 
					
						
							|  |  |  |     let optionHash = localStorage.getItem(`${gameName}-hash`); | 
					
						
							|  |  |  |     if (!optionHash) { | 
					
						
							| 
									
										
										
										
											2021-09-17 21:23:31 -04:00
										 |  |  |       // If no hash data has been set before, set it now
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |       optionHash = md5(JSON.stringify(results)); | 
					
						
							|  |  |  |       localStorage.setItem(`${gameName}-hash`, optionHash); | 
					
						
							| 
									
										
										
										
											2022-04-04 18:54:40 -04:00
										 |  |  |       localStorage.removeItem(gameName); | 
					
						
							| 
									
										
										
										
											2021-09-17 21:23:31 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     if (optionHash !== md5(JSON.stringify(results))) { | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |       showUserMessage( | 
					
						
							|  |  |  |           'Your options are out of date! Click here to update them! Be aware this will reset them all to default.' | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |       document.getElementById('user-message').addEventListener('click', resetOptions); | 
					
						
							| 
									
										
										
										
											2021-09-17 21:23:31 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 05:30:03 -05:00
										 |  |  |     // Page setup
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     createDefaultOptions(results); | 
					
						
							| 
									
										
										
										
											2022-04-04 19:36:56 -04:00
										 |  |  |     buildUI(results); | 
					
						
							| 
									
										
										
										
											2020-12-04 05:30:03 -05:00
										 |  |  |     adjustHeaderWidth(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Event listeners
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     document.getElementById('export-options').addEventListener('click', () => exportOptions()); | 
					
						
							| 
									
										
										
										
											2021-09-16 17:15:25 -04:00
										 |  |  |     document.getElementById('generate-race').addEventListener('click', () => generateGame(true)); | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |     document.getElementById('generate-game').addEventListener('click', () => generateGame()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 05:30:03 -05:00
										 |  |  |     // Name input field
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     const playerOptions = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |     const nameInput = document.getElementById('player-name'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     nameInput.addEventListener('keyup', (event) => updateBaseOption(event)); | 
					
						
							|  |  |  |     nameInput.value = playerOptions.name; | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Presets
 | 
					
						
							|  |  |  |     const presetSelect = document.getElementById('game-options-preset'); | 
					
						
							|  |  |  |     presetSelect.addEventListener('change', (event) => setPresets(results, event.target.value)); | 
					
						
							|  |  |  |     for (const preset in results['presetOptions']) { | 
					
						
							|  |  |  |       const presetOption = document.createElement('option'); | 
					
						
							|  |  |  |       presetOption.innerText = preset; | 
					
						
							|  |  |  |       presetSelect.appendChild(presetOption); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     presetSelect.value = localStorage.getItem(`${gameName}-preset`); | 
					
						
							|  |  |  |     results['presetOptions']['__default'] = {}; | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |   }).catch((e) => { | 
					
						
							|  |  |  |     console.error(e); | 
					
						
							| 
									
										
										
										
											2021-07-24 23:20:46 -04:00
										 |  |  |     const url = new URL(window.location.href); | 
					
						
							| 
									
										
										
										
											2021-07-25 18:07:03 -04:00
										 |  |  |     window.location.replace(`${url.protocol}//${url.hostname}/page-not-found`); | 
					
						
							| 
									
										
										
										
											2020-12-04 05:30:03 -05:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const resetOptions = () => { | 
					
						
							| 
									
										
										
										
											2021-09-17 21:23:31 -04:00
										 |  |  |   localStorage.removeItem(gameName); | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |   localStorage.removeItem(`${gameName}-hash`); | 
					
						
							|  |  |  |   localStorage.removeItem(`${gameName}-preset`); | 
					
						
							| 
									
										
										
										
											2021-09-17 21:23:31 -04:00
										 |  |  |   window.location.reload(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const fetchOptionData = () => new Promise((resolve, reject) => { | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   const ajax = new XMLHttpRequest(); | 
					
						
							|  |  |  |   ajax.onreadystatechange = () => { | 
					
						
							|  |  |  |     if (ajax.readyState !== 4) { return; } | 
					
						
							|  |  |  |     if (ajax.status !== 200) { | 
					
						
							|  |  |  |       reject(ajax.responseText); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     try{ resolve(JSON.parse(ajax.responseText)); } | 
					
						
							|  |  |  |     catch(error){ reject(error); } | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   ajax.open('GET', `${window.location.origin}/static/generated/player-options/${gameName}.json`, true); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   ajax.send(); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const createDefaultOptions = (optionData) => { | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  |   if (!localStorage.getItem(gameName)) { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     const newOptions = { | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  |       [gameName]: {}, | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     for (let baseOption of Object.keys(optionData.baseOptions)){ | 
					
						
							|  |  |  |       newOptions[baseOption] = optionData.baseOptions[baseOption]; | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     for (let gameOption of Object.keys(optionData.gameOptions)){ | 
					
						
							|  |  |  |       newOptions[gameName][gameOption] = optionData.gameOptions[gameOption].defaultValue; | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     localStorage.setItem(gameName, JSON.stringify(newOptions)); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!localStorage.getItem(`${gameName}-preset`)) { | 
					
						
							|  |  |  |     localStorage.setItem(`${gameName}-preset`, '__default'); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const buildUI = (optionData) => { | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   // Game Options
 | 
					
						
							|  |  |  |   const leftGameOpts = {}; | 
					
						
							|  |  |  |   const rightGameOpts = {}; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   Object.keys(optionData.gameOptions).forEach((key, index) => { | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |     if (index < Object.keys(optionData.gameOptions).length / 2) { | 
					
						
							|  |  |  |       leftGameOpts[key] = optionData.gameOptions[key]; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       rightGameOpts[key] = optionData.gameOptions[key]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  |   document.getElementById('game-options-left').appendChild(buildOptionsTable(leftGameOpts)); | 
					
						
							|  |  |  |   document.getElementById('game-options-right').appendChild(buildOptionsTable(rightGameOpts)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const buildOptionsTable = (options, romOpts = false) => { | 
					
						
							|  |  |  |   const currentOptions = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |   const table = document.createElement('table'); | 
					
						
							|  |  |  |   const tbody = document.createElement('tbody'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   Object.keys(options).forEach((option) => { | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |     const tr = document.createElement('tr'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // td Left
 | 
					
						
							|  |  |  |     const tdl = document.createElement('td'); | 
					
						
							|  |  |  |     const label = document.createElement('label'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     label.textContent = `${options[option].displayName}: `; | 
					
						
							|  |  |  |     label.setAttribute('for', option); | 
					
						
							| 
									
										
										
										
											2022-08-21 00:58:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const questionSpan = document.createElement('span'); | 
					
						
							|  |  |  |     questionSpan.classList.add('interactive'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     questionSpan.setAttribute('data-tooltip', options[option].description); | 
					
						
							| 
									
										
										
										
											2022-08-21 00:58:46 +02:00
										 |  |  |     questionSpan.innerText = '(?)'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     label.appendChild(questionSpan); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |     tdl.appendChild(label); | 
					
						
							|  |  |  |     tr.appendChild(tdl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // td Right
 | 
					
						
							|  |  |  |     const tdr = document.createElement('td'); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |     let element = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |     const randomButton = document.createElement('button'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |     switch(options[option].type) { | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |       case 'select': | 
					
						
							|  |  |  |         element = document.createElement('div'); | 
					
						
							|  |  |  |         element.classList.add('select-container'); | 
					
						
							|  |  |  |         let select = document.createElement('select'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         select.setAttribute('id', option); | 
					
						
							|  |  |  |         select.setAttribute('data-key', option); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         if (romOpts) { select.setAttribute('data-romOpt', '1'); } | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         options[option].options.forEach((opt) => { | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |           const optionElement = document.createElement('option'); | 
					
						
							|  |  |  |           optionElement.setAttribute('value', opt.value); | 
					
						
							|  |  |  |           optionElement.innerText = opt.name; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           if ((isNaN(currentOptions[gameName][option]) && | 
					
						
							|  |  |  |             (parseInt(opt.value, 10) === parseInt(currentOptions[gameName][option]))) || | 
					
						
							|  |  |  |             (opt.value === currentOptions[gameName][option])) | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |           { | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |             optionElement.selected = true; | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |           select.appendChild(optionElement); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         select.addEventListener('change', (event) => updateGameOption(event.target)); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         element.appendChild(select); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Randomize button
 | 
					
						
							|  |  |  |         randomButton.innerText = '🎲'; | 
					
						
							|  |  |  |         randomButton.classList.add('randomize-button'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         randomButton.setAttribute('data-key', option); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |         randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); | 
					
						
							| 
									
										
										
										
											2023-06-22 21:12:22 -05:00
										 |  |  |         randomButton.addEventListener('click', (event) => toggleRandomize(event, select)); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         if (currentOptions[gameName][option] === 'random') { | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |           randomButton.classList.add('active'); | 
					
						
							|  |  |  |           select.disabled = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         element.appendChild(randomButton); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case 'range': | 
					
						
							|  |  |  |         element = document.createElement('div'); | 
					
						
							|  |  |  |         element.classList.add('range-container'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let range = document.createElement('input'); | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |         range.setAttribute('id', option); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         range.setAttribute('type', 'range'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         range.setAttribute('data-key', option); | 
					
						
							|  |  |  |         range.setAttribute('min', options[option].min); | 
					
						
							|  |  |  |         range.setAttribute('max', options[option].max); | 
					
						
							|  |  |  |         range.value = currentOptions[gameName][option]; | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         range.addEventListener('change', (event) => { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           document.getElementById(`${option}-value`).innerText = event.target.value; | 
					
						
							|  |  |  |           updateGameOption(event.target); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         element.appendChild(range); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let rangeVal = document.createElement('span'); | 
					
						
							|  |  |  |         rangeVal.classList.add('range-value'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         rangeVal.setAttribute('id', `${option}-value`); | 
					
						
							|  |  |  |         rangeVal.innerText = currentOptions[gameName][option] !== 'random' ? | 
					
						
							|  |  |  |           currentOptions[gameName][option] : options[option].defaultValue; | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         element.appendChild(rangeVal); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Randomize button
 | 
					
						
							|  |  |  |         randomButton.innerText = '🎲'; | 
					
						
							|  |  |  |         randomButton.classList.add('randomize-button'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         randomButton.setAttribute('data-key', option); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |         randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); | 
					
						
							| 
									
										
										
										
											2023-06-22 21:12:22 -05:00
										 |  |  |         randomButton.addEventListener('click', (event) => toggleRandomize(event, range)); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         if (currentOptions[gameName][option] === 'random') { | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |           randomButton.classList.add('active'); | 
					
						
							|  |  |  |           range.disabled = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         element.appendChild(randomButton); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |       case 'named_range': | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         element = document.createElement('div'); | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         element.classList.add('named-range-container'); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Build the select element
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         let namedRangeSelect = document.createElement('select'); | 
					
						
							|  |  |  |         namedRangeSelect.setAttribute('data-key', option); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         Object.keys(options[option].value_names).forEach((presetName) => { | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |           let presetOption = document.createElement('option'); | 
					
						
							|  |  |  |           presetOption.innerText = presetName; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           presetOption.value = options[option].value_names[presetName]; | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |           const words = presetOption.innerText.split('_'); | 
					
						
							| 
									
										
										
										
											2023-01-02 12:25:33 -06:00
										 |  |  |           for (let i = 0; i < words.length; i++) { | 
					
						
							|  |  |  |             words[i] = words[i][0].toUpperCase() + words[i].substring(1); | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |           presetOption.innerText = words.join(' '); | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |           namedRangeSelect.appendChild(presetOption); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  |         let customOption = document.createElement('option'); | 
					
						
							|  |  |  |         customOption.innerText = 'Custom'; | 
					
						
							|  |  |  |         customOption.value = 'custom'; | 
					
						
							|  |  |  |         customOption.selected = true; | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         namedRangeSelect.appendChild(customOption); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         if (Object.values(options[option].value_names).includes(Number(currentOptions[gameName][option]))) { | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |           namedRangeSelect.value = Number(currentOptions[gameName][option]); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Build range element
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         let namedRangeWrapper = document.createElement('div'); | 
					
						
							|  |  |  |         namedRangeWrapper.classList.add('named-range-wrapper'); | 
					
						
							|  |  |  |         let namedRange = document.createElement('input'); | 
					
						
							|  |  |  |         namedRange.setAttribute('type', 'range'); | 
					
						
							|  |  |  |         namedRange.setAttribute('data-key', option); | 
					
						
							|  |  |  |         namedRange.setAttribute('min', options[option].min); | 
					
						
							|  |  |  |         namedRange.setAttribute('max', options[option].max); | 
					
						
							|  |  |  |         namedRange.value = currentOptions[gameName][option]; | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Build rage value element
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         let namedRangeVal = document.createElement('span'); | 
					
						
							|  |  |  |         namedRangeVal.classList.add('range-value'); | 
					
						
							|  |  |  |         namedRangeVal.setAttribute('id', `${option}-value`); | 
					
						
							|  |  |  |         namedRangeVal.innerText = currentOptions[gameName][option] !== 'random' ? | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           currentOptions[gameName][option] : options[option].defaultValue; | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Configure select event listener
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         namedRangeSelect.addEventListener('change', (event) => { | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |           if (event.target.value === 'custom') { return; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Update range slider
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |           namedRange.value = event.target.value; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           document.getElementById(`${option}-value`).innerText = event.target.value; | 
					
						
							|  |  |  |           updateGameOption(event.target); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Configure range event handler
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         namedRange.addEventListener('change', (event) => { | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |           // Update select element
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |           namedRangeSelect.value = | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |             (Object.values(options[option].value_names).includes(parseInt(event.target.value))) ? | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |             parseInt(event.target.value) : 'custom'; | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |           document.getElementById(`${option}-value`).innerText = event.target.value; | 
					
						
							|  |  |  |           updateGameOption(event.target); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         element.appendChild(namedRangeSelect); | 
					
						
							|  |  |  |         namedRangeWrapper.appendChild(namedRange); | 
					
						
							|  |  |  |         namedRangeWrapper.appendChild(namedRangeVal); | 
					
						
							|  |  |  |         element.appendChild(namedRangeWrapper); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Randomize button
 | 
					
						
							|  |  |  |         randomButton.innerText = '🎲'; | 
					
						
							|  |  |  |         randomButton.classList.add('randomize-button'); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         randomButton.setAttribute('data-key', option); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |         randomButton.setAttribute('data-tooltip', 'Toggle randomization for this option!'); | 
					
						
							|  |  |  |         randomButton.addEventListener('click', (event) => toggleRandomize( | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |             event, namedRange, namedRangeSelect) | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         if (currentOptions[gameName][option] === 'random') { | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |           randomButton.classList.add('active'); | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |           namedRange.disabled = true; | 
					
						
							|  |  |  |           namedRangeSelect.disabled = true; | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-25 00:10:52 +01:00
										 |  |  |         namedRangeWrapper.appendChild(randomButton); | 
					
						
							| 
									
										
										
										
											2022-06-12 23:33:14 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |       default: | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |         console.error(`Ignoring unknown option type: ${options[option].type} with name ${option}`); | 
					
						
							| 
									
										
										
										
											2021-07-25 19:04:08 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tdr.appendChild(element); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  |     tr.appendChild(tdr); | 
					
						
							|  |  |  |     tbody.appendChild(tr); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   table.appendChild(tbody); | 
					
						
							|  |  |  |   return table; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  | const setPresets = (optionsData, presetName) => { | 
					
						
							|  |  |  |   const defaults = optionsData['gameOptions']; | 
					
						
							|  |  |  |   const preset = optionsData['presetOptions'][presetName]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   localStorage.setItem(`${gameName}-preset`, presetName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!preset) { | 
					
						
							|  |  |  |     console.error(`No presets defined for preset name: '${presetName}'`); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const updateOptionElement = (option, presetValue) => { | 
					
						
							|  |  |  |     const optionElement = document.querySelector(`#${option}[data-key='${option}']`); | 
					
						
							|  |  |  |     const randomElement = document.querySelector(`.randomize-button[data-key='${option}']`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (presetValue === 'random') { | 
					
						
							|  |  |  |       randomElement.classList.add('active'); | 
					
						
							|  |  |  |       optionElement.disabled = true; | 
					
						
							|  |  |  |       updateGameOption(randomElement, false); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       optionElement.value = presetValue; | 
					
						
							|  |  |  |       randomElement.classList.remove('active'); | 
					
						
							|  |  |  |       optionElement.disabled = undefined; | 
					
						
							|  |  |  |       updateGameOption(optionElement, false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (const option in defaults) { | 
					
						
							|  |  |  |     let presetValue = preset[option]; | 
					
						
							|  |  |  |     if (presetValue === undefined) { | 
					
						
							|  |  |  |       // Using the default value if not set in presets.
 | 
					
						
							|  |  |  |       presetValue = defaults[option]['defaultValue']; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (defaults[option].type) { | 
					
						
							|  |  |  |       case 'range': | 
					
						
							|  |  |  |         const numberElement = document.querySelector(`#${option}-value`); | 
					
						
							|  |  |  |         if (presetValue === 'random') { | 
					
						
							|  |  |  |           numberElement.innerText = defaults[option]['defaultValue'] === 'random' | 
					
						
							|  |  |  |               ? defaults[option]['min'] // A fallback so we don't print 'random' in the UI.
 | 
					
						
							|  |  |  |               : defaults[option]['defaultValue']; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           numberElement.innerText = presetValue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         updateOptionElement(option, presetValue); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       case 'select': { | 
					
						
							|  |  |  |         updateOptionElement(option, presetValue); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-29 00:11:17 +01:00
										 |  |  |       case 'named_range': { | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |         const selectElement = document.querySelector(`select[data-key='${option}']`); | 
					
						
							|  |  |  |         const rangeElement = document.querySelector(`input[data-key='${option}']`); | 
					
						
							|  |  |  |         const randomElement = document.querySelector(`.randomize-button[data-key='${option}']`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (presetValue === 'random') { | 
					
						
							|  |  |  |           randomElement.classList.add('active'); | 
					
						
							|  |  |  |           selectElement.disabled = true; | 
					
						
							|  |  |  |           rangeElement.disabled = true; | 
					
						
							|  |  |  |           updateGameOption(randomElement, false); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           rangeElement.value = presetValue; | 
					
						
							|  |  |  |           selectElement.value = Object.values(defaults[option]['value_names']).includes(parseInt(presetValue)) ? | 
					
						
							|  |  |  |               parseInt(presetValue) : 'custom'; | 
					
						
							|  |  |  |           document.getElementById(`${option}-value`).innerText = presetValue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           randomElement.classList.remove('active'); | 
					
						
							|  |  |  |           selectElement.disabled = undefined; | 
					
						
							|  |  |  |           rangeElement.disabled = undefined; | 
					
						
							|  |  |  |           updateGameOption(rangeElement, false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         console.warn(`Ignoring preset value for unknown option type: ${defaults[option].type} with name ${option}`); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 21:12:22 -05:00
										 |  |  | const toggleRandomize = (event, inputElement, optionalSelectElement = null) => { | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |   const active = event.target.classList.contains('active'); | 
					
						
							|  |  |  |   const randomButton = event.target; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (active) { | 
					
						
							|  |  |  |     randomButton.classList.remove('active'); | 
					
						
							| 
									
										
										
										
											2023-06-22 21:12:22 -05:00
										 |  |  |     inputElement.disabled = undefined; | 
					
						
							|  |  |  |     if (optionalSelectElement) { | 
					
						
							|  |  |  |       optionalSelectElement.disabled = undefined; | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |     } | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     randomButton.classList.add('active'); | 
					
						
							| 
									
										
										
										
											2023-06-22 21:12:22 -05:00
										 |  |  |     inputElement.disabled = true; | 
					
						
							|  |  |  |     if (optionalSelectElement) { | 
					
						
							|  |  |  |       optionalSelectElement.disabled = true; | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     updateGameOption(active ? inputElement : randomButton); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const updateBaseOption = (event) => { | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  |   const options = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							|  |  |  |   options[event.target.getAttribute('data-key')] = isNaN(event.target.value) ? | 
					
						
							|  |  |  |     event.target.value : parseInt(event.target.value); | 
					
						
							|  |  |  |   localStorage.setItem(gameName, JSON.stringify(options)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  | const updateGameOption = (optionElement, toggleCustomPreset = true) => { | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  |   const options = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (toggleCustomPreset) { | 
					
						
							|  |  |  |     localStorage.setItem(`${gameName}-preset`, '__custom'); | 
					
						
							|  |  |  |     const presetElement = document.getElementById('game-options-preset'); | 
					
						
							|  |  |  |     presetElement.value = '__custom'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   if (optionElement.classList.contains('randomize-button')) { | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |     // If the event passed in is the randomize button, then we know what we must do.
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     options[gameName][optionElement.getAttribute('data-key')] = 'random'; | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     options[gameName][optionElement.getAttribute('data-key')] = isNaN(optionElement.value) ? | 
					
						
							|  |  |  |       optionElement.value : parseInt(optionElement.value, 10); | 
					
						
							| 
									
										
										
										
											2022-11-12 21:03:44 -06:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 23:09:34 -04:00
										 |  |  |   localStorage.setItem(gameName, JSON.stringify(options)); | 
					
						
							| 
									
										
										
										
											2020-12-03 18:27:32 -05:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  | const exportOptions = () => { | 
					
						
							|  |  |  |   const options = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							| 
									
										
										
										
											2023-11-16 04:37:06 -06:00
										 |  |  |   const preset = localStorage.getItem(`${gameName}-preset`); | 
					
						
							|  |  |  |   switch (preset) { | 
					
						
							|  |  |  |     case '__default': | 
					
						
							|  |  |  |       options['description'] = `Generated by https://archipelago.gg with the default preset.`; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case '__custom': | 
					
						
							|  |  |  |       options['description'] = `Generated by https://archipelago.gg.`; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       options['description'] = `Generated by https://archipelago.gg with the ${preset} preset.`; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-24 16:50:32 -05:00
										 |  |  |   if (!options.name || options.name.toString().trim().length === 0) { | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  |     return showUserMessage('You must enter a player name!'); | 
					
						
							| 
									
										
										
										
											2022-01-19 00:38:17 -05:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   const yamlText = jsyaml.safeDump(options, { noCompatMode: true }).replaceAll(/'(\d+)':/g, (x, y) => `${y}:`); | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |   download(`${document.getElementById('player-name').value}.yaml`, yamlText); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Create an anchor and trigger a download of a text file. */ | 
					
						
							|  |  |  | const download = (filename, text) => { | 
					
						
							|  |  |  |   const downloadLink = document.createElement('a'); | 
					
						
							|  |  |  |   downloadLink.setAttribute('href','data:text/yaml;charset=utf-8,'+ encodeURIComponent(text)) | 
					
						
							|  |  |  |   downloadLink.setAttribute('download', filename); | 
					
						
							|  |  |  |   downloadLink.style.display = 'none'; | 
					
						
							|  |  |  |   document.body.appendChild(downloadLink); | 
					
						
							|  |  |  |   downloadLink.click(); | 
					
						
							|  |  |  |   document.body.removeChild(downloadLink); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const generateGame = (raceMode = false) => { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |   const options = JSON.parse(localStorage.getItem(gameName)); | 
					
						
							|  |  |  |   if (!options.name || options.name.toLowerCase() === 'player' || options.name.trim().length === 0) { | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  |     return showUserMessage('You must enter a player name!'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |   axios.post('/api/generate', { | 
					
						
							| 
									
										
										
										
											2023-10-23 19:20:08 -05:00
										 |  |  |     weights: { player: options }, | 
					
						
							|  |  |  |     presetData: { player: options }, | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |     playerCount: 1, | 
					
						
							| 
									
										
										
										
											2023-06-23 04:01:09 +02:00
										 |  |  |     spoiler: 3, | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |     race: raceMode ? '1' : '0', | 
					
						
							| 
									
										
										
										
											2020-12-04 00:42:33 -05:00
										 |  |  |   }).then((response) => { | 
					
						
							|  |  |  |     window.location.href = response.data.url; | 
					
						
							| 
									
										
										
										
											2021-05-13 21:33:56 -04:00
										 |  |  |   }).catch((error) => { | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  |     let userMessage = 'Something went wrong and your game could not be generated.'; | 
					
						
							| 
									
										
										
										
											2021-07-21 18:08:15 +02:00
										 |  |  |     if (error.response.data.text) { | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  |       userMessage += ' ' + error.response.data.text; | 
					
						
							| 
									
										
										
										
											2021-07-21 18:08:15 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  |     showUserMessage(userMessage); | 
					
						
							| 
									
										
										
										
											2021-05-13 21:33:56 -04:00
										 |  |  |     console.error(error); | 
					
						
							| 
									
										
										
										
											2020-12-04 00:40:57 -05:00
										 |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2022-01-19 00:54:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | const showUserMessage = (message) => { | 
					
						
							|  |  |  |   const userMessage = document.getElementById('user-message'); | 
					
						
							|  |  |  |     userMessage.innerText = message; | 
					
						
							|  |  |  |     userMessage.classList.add('visible'); | 
					
						
							|  |  |  |     window.scrollTo(0, 0); | 
					
						
							|  |  |  |     userMessage.addEventListener('click', () => { | 
					
						
							|  |  |  |       userMessage.classList.remove('visible'); | 
					
						
							|  |  |  |       userMessage.addEventListener('click', hideUserMessage); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const hideUserMessage = () => { | 
					
						
							|  |  |  |   const userMessage = document.getElementById('user-message'); | 
					
						
							|  |  |  |   userMessage.classList.remove('visible'); | 
					
						
							|  |  |  |   userMessage.removeEventListener('click', hideUserMessage); | 
					
						
							|  |  |  | }; |