A keybinding tool for defending quickly in NationStates.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

51 righe
2.0 KiB

  1. document.querySelector('#content').innerHTML = `<h1>Raspberry Settings</h1>
  2. <fieldset>
  3. <legend>Keys</legend>
  4. <table>
  5. <tbody id="keys">
  6. </tbody>
  7. </table>
  8. </fieldset>`;
  9. async function addKeySetter(functionName: string, displayName?: string)
  10. {
  11. if (displayName === undefined)
  12. displayName = pretty(functionName);
  13. const setKeyInput: HTMLInputElement = document.createElement('input');
  14. setKeyInput.type = 'button';
  15. setKeyInput.value = 'Set';
  16. setKeyInput.classList.add('button');
  17. setKeyInput.addEventListener('click', async (e: MouseEvent): Promise<void> =>
  18. {
  19. console.log(`Setting ${functionName}`);
  20. const key: string = (document.querySelector(`#${functionName}-key`) as HTMLInputElement).value.toUpperCase();
  21. await setStorageValue(functionName, key);
  22. });
  23. const tr: HTMLTableRowElement = document.createElement('tr');
  24. const td1: HTMLTableDataCellElement = document.createElement('td');
  25. td1.innerHTML += `<label>${displayName}</label>`;
  26. const td2: HTMLTableDataCellElement = document.createElement('td');
  27. td2.innerHTML += `<input type="text" id="${functionName}-key" value="${await getStorageValue(functionName) || '?'}">`;
  28. const td3: HTMLTableDataCellElement = document.createElement('td');
  29. td3.appendChild(setKeyInput);
  30. tr.appendChild(td1);
  31. tr.appendChild(td2);
  32. tr.appendChild(td3);
  33. document.querySelector('#keys').appendChild(tr);
  34. // This doesn't work apparently
  35. /*document.querySelector('#keys').innerHTML +=
  36. `<tr><td><label>${displayName}</label></td><td><input type="text" id="${functionName}-key" value="${await getStorageValue(functionName) || '?'}"></td><td><input type="button" class="button" id="set-${functionName}-key" value="Set"></td></tr>`;*/
  37. }
  38. (async () =>
  39. {
  40. // Set up the keybind setting form
  41. for (let i = 0; i < keybinds.length; i++) {
  42. if (keybinds[i].displayName)
  43. await addKeySetter(keybinds[i].functionName, keybinds[i].displayName);
  44. else
  45. await addKeySetter(keybinds[i].functionName);
  46. }
  47. })();