diff --git a/src/main.ts b/src/main.ts index 8f58512..8a0625d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,14 @@ interface Keybind modifiedCallback: Function | null; } +let notyf = new Notyf({ + duration: 3000, + position: { + x: 'right', + y: 'top' + } +}); + const keybinds: Keybind[] = [ { functionName: 'move', @@ -181,6 +189,59 @@ const keybinds: Keybind[] = [ } }, modifiedCallback: null + }, + { + functionName: 'prep', + displayName: null, + callback: async () => + { + const switchers = await getStorageValue('switchers'); + const password = await getStorageValue('password'); + const jumpPoint: string = await getStorageValue('jp'); + const moveButton: HTMLButtonElement = + document.querySelector('button[name=move_region]') as HTMLButtonElement; + if (!switchers || !password) + return; + const currentSwitcher: number = await getStorageValue('currentswitcher'); + if (urlParams['page'] === 'un' && urlParams['template-overall'] === 'none') + (document.querySelector('button[type=submit]') as HTMLButtonElement).click(); + else if (urlParams['page'] === 'UN_status') { + const resendButton = document.querySelector('body > p.error > a') as HTMLAnchorElement; + if (resendButton !== null) + resendButton.click(); + else + window.location.href = `/template-overall=none/region=${jumpPoint}`; + } + else if (urlParams['region'] === jumpPoint && moveButton !== null) + moveButton.click(); + else if (urlParams['page'] === 'change_region' || (urlParams['region'] && moveButton === null)) { + if (currentSwitcher === (switchers.length - 1)) { + await setStorageValue('currentswitcher', 0); + window.location.href = + `/template-overall=none/page=un?nation=${switchers[0]}&password=${password}&logging_in=1`; + } + else { + await setStorageValue('currentswitcher', currentSwitcher + 1); + window.location.href = + `/template-overall=none/page=un?nation=${switchers[currentSwitcher + 1]}&password=${password}&logging_in=1`; + } + } + else { + window.location.href = + `/template-overall=none/page=un?nation=${switchers[currentSwitcher]}&password=${password}&logging_in=1`; + } + }, + modifiedCallback: async () => + { + const switchers = await getStorageValue('switchers'); + if (urlParams['nation']) { + const newIndex = switchers.indexOf(urlParams['nation']); + if (newIndex !== -1) { + await setStorageValue('currentswitcher', newIndex); + notyf.success(`Synced index with ${urlParams['nation']}`); + } + } + } } ]; @@ -213,4 +274,8 @@ document.addEventListener('keyup', (e: KeyboardEvent) => await setStorageValue('jp', 'artificial_solar_system'); if (await getStorageValue('nationstoendorse') === undefined) await setStorageValue('nationstoendorse', []); + if ((await getStorageValue('switchers') !== undefined) && + (await getStorageValue('currentswitcher') === undefined)) { + await setStorageValue('currentswitcher', 0); + } })(); \ No newline at end of file diff --git a/src/settings.ts b/src/settings.ts index c1a6b91..94f65e0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -44,8 +44,11 @@ document.querySelector('#content').innerHTML = `

Gauntlet Settings

*/ async function addKeySetter(keybind: Keybind) { + // If no display name was provided, simply give it the title case version of the function name if (keybind.displayName === null) keybind.displayName = pretty(keybind.functionName); + + // Create the "Set" button const setKeyInput: HTMLInputElement = document.createElement('input'); setKeyInput.type = 'button'; setKeyInput.value = 'Set'; @@ -58,10 +61,12 @@ async function addKeySetter(keybind: Keybind) await setStorageValue(keybind.functionName, key); }); + // Set up a table row so that each of the buttons and text fields line up const tr: HTMLTableRowElement = document.createElement('tr'); const td1: HTMLTableDataCellElement = document.createElement('td'); td1.innerHTML += ``; const td2: HTMLTableDataCellElement = document.createElement('td'); + // Give the text field the value of its currently stored key td2.innerHTML += ``; const td3: HTMLTableDataCellElement = document.createElement('td'); @@ -100,8 +105,19 @@ async function setSwitchers(e: MouseEvent): Promise for (let i = 0; i < keybinds.length; i++) await addKeySetter(keybinds[i]); - // Other settings + // Set known values (document.querySelector('#jump-point') as HTMLInputElement).value = await getStorageValue('jp'); + (document.querySelector('#prep-password') as HTMLInputElement).value = + await getStorageValue('password') ?? ''; + const switchers: string[] = await getStorageValue('switchers'); + if (switchers) { + const switchersList = document.querySelector('#switchers') as HTMLTextAreaElement; + for (let i = 0; i < switchers.length; i++) { + switchersList.value += `${switchers[i]}\n`; + } + } + + // Other settings document.querySelector('#set-jump-point').addEventListener('click', setJumpPoint); document.querySelector('#set-prep-password').addEventListener('click', setPassword); document.querySelector('#set-switchers').addEventListener('click', setSwitchers); diff --git a/tsconfig.json b/tsconfig.json index cec0517..7db74f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,6 @@ ], "exclude": [ "node_modules", - "src/ts/notyf.min" + "src/notyf.min" ] } \ No newline at end of file