Преглед изворни кода

finished basic prep features

master
Haku пре 3 година
родитељ
комит
b68cc41258
3 измењених фајлова са 83 додато и 2 уклоњено
  1. +65
    -0
      src/main.ts
  2. +17
    -1
      src/settings.ts
  3. +1
    -1
      tsconfig.json

+ 65
- 0
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);
}
})();

+ 17
- 1
src/settings.ts Прегледај датотеку

@@ -44,8 +44,11 @@ document.querySelector('#content').innerHTML = `<h1>Gauntlet Settings</h1>
*/
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 += `<label>${keybind.displayName}</label>`;
const td2: HTMLTableDataCellElement = document.createElement('td');
// Give the text field the value of its currently stored key
td2.innerHTML +=
`<input type="text" id="${keybind.functionName}-key" value="${await getStorageValue(keybind.functionName) || '?'}">`;
const td3: HTMLTableDataCellElement = document.createElement('td');
@@ -100,8 +105,19 @@ async function setSwitchers(e: MouseEvent): Promise<void>
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);

+ 1
- 1
tsconfig.json Прегледај датотеку

@@ -10,6 +10,6 @@
],
"exclude": [
"node_modules",
"src/ts/notyf.min"
"src/notyf.min"
]
}

Loading…
Откажи
Сачувај