Browse Source

adjusted line lengths to be below maximum recommended line length

master
Haku 3 years ago
parent
commit
0abb5d8b09
2 changed files with 34 additions and 20 deletions
  1. +26
    -13
      src/main.ts
  2. +8
    -7
      src/settings.ts

+ 26
- 13
src/main.ts View File

@@ -11,7 +11,8 @@ const keybinds: Keybind[] = [
functionName: 'move', functionName: 'move',
displayName: null, displayName: null,
callback: () => { callback: () => {
const moveButton: HTMLButtonElement = document.querySelector('button[name=move_region]') as HTMLButtonElement;
const moveButton: HTMLButtonElement =
document.querySelector('button[name=move_region]') as HTMLButtonElement;
if (moveButton) if (moveButton)
moveButton.click(); moveButton.click();
}, },
@@ -21,7 +22,8 @@ const keybinds: Keybind[] = [
functionName: 'endorse', functionName: 'endorse',
displayName: null, displayName: null,
callback: () => { callback: () => {
const endorseButton: HTMLButtonElement = (document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
const endorseButton: HTMLButtonElement =
(document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
if (endorseButton) if (endorseButton)
endorseButton.click(); endorseButton.click();
}, },
@@ -31,7 +33,8 @@ const keybinds: Keybind[] = [
} }
else if (urlParams['nation']) { else if (urlParams['nation']) {
let nationsToEndorse: string[] = await getStorageValue('nationstoendorse'); let nationsToEndorse: string[] = await getStorageValue('nationstoendorse');
const endorseButton: HTMLButtonElement = (document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
const endorseButton: HTMLButtonElement =
(document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
if (endorseButton && (nationsToEndorse.indexOf(urlParams['nation']) !== -1)) if (endorseButton && (nationsToEndorse.indexOf(urlParams['nation']) !== -1))
endorseButton.click(); endorseButton.click();
else if (nationsToEndorse.indexOf(urlParams['nation']) !== -1) { else if (nationsToEndorse.indexOf(urlParams['nation']) !== -1) {
@@ -57,7 +60,8 @@ const keybinds: Keybind[] = [
functionName: 'dossier', functionName: 'dossier',
displayName: null, displayName: null,
callback: () => { callback: () => {
const dossierButton: HTMLButtonElement = document.querySelector('button[value=add]') as HTMLButtonElement;
const dossierButton: HTMLButtonElement =
document.querySelector('button[value=add]') as HTMLButtonElement;
if (dossierButton) if (dossierButton)
dossierButton.click(); dossierButton.click();
}, },
@@ -67,7 +71,8 @@ const keybinds: Keybind[] = [
} }
else if (urlParams['nation']) { else if (urlParams['nation']) {
let nationsToDossier: string[] = await getStorageValue('nationstodossier'); let nationsToDossier: string[] = await getStorageValue('nationstodossier');
const dossierButton: HTMLButtonElement = document.querySelector('button[value=add]') as HTMLButtonElement;
const dossierButton: HTMLButtonElement =
document.querySelector('button[value=add]') as HTMLButtonElement;
if (dossierButton && (nationsToDossier.indexOf(urlParams['nation']) !== -1)) if (dossierButton && (nationsToDossier.indexOf(urlParams['nation']) !== -1))
dossierButton.click(); dossierButton.click();
else { else {
@@ -81,7 +86,8 @@ const keybinds: Keybind[] = [
} }
else if (urlParams['page'] === 'dossier') { else if (urlParams['page'] === 'dossier') {
let nationsToDossier: string[] = await getStorageValue('nationstodossier'); let nationsToDossier: string[] = await getStorageValue('nationstodossier');
const currentNation: string = new RegExp('nation=(.+)$').exec((document.querySelector('.info > a') as HTMLAnchorElement).href)[1];
const currentNation: string = new RegExp('nation=(.+)$')
.exec((document.querySelector('.info > a') as HTMLAnchorElement).href)[1];
const nextNation: string = nationsToDossier[nationsToDossier.indexOf(currentNation) + 1]; const nextNation: string = nationsToDossier[nationsToDossier.indexOf(currentNation) + 1];
if (!nextNation) if (!nextNation)
return; return;
@@ -95,7 +101,8 @@ const keybinds: Keybind[] = [
functionName: 'backtojp', functionName: 'backtojp',
displayName: "Move Back to Jump Point", displayName: "Move Back to Jump Point",
callback: async () => { callback: async () => {
const moveButton: HTMLButtonElement = document.querySelector('button[name=move_region]') as HTMLButtonElement;
const moveButton: HTMLButtonElement =
document.querySelector('button[name=move_region]') as HTMLButtonElement;
const jumpPoint: string = await getStorageValue('jp'); const jumpPoint: string = await getStorageValue('jp');
if ((urlParams['region'] === jumpPoint) && moveButton) if ((urlParams['region'] === jumpPoint) && moveButton)
moveButton.click(); moveButton.click();
@@ -108,11 +115,13 @@ const keybinds: Keybind[] = [
functionName: 'endodel', functionName: 'endodel',
displayName: "Endorse WA Delegate", displayName: "Endorse WA Delegate",
callback: () => { callback: () => {
const delegate: HTMLAnchorElement = document.querySelector('#regioncontent > p:nth-child(1) > a') as HTMLAnchorElement;
const delegate: HTMLAnchorElement =
document.querySelector('#regioncontent > p:nth-child(1) > a') as HTMLAnchorElement;
if (urlParams['region']) if (urlParams['region'])
delegate.click(); delegate.click();
else if (urlParams['nation']) { else if (urlParams['nation']) {
const endorseButton: HTMLButtonElement = (document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
const endorseButton: HTMLButtonElement =
(document.querySelector('button[class="endorse button icon wa"]') as HTMLButtonElement);
if (endorseButton) if (endorseButton)
endorseButton.click(); endorseButton.click();
} }
@@ -133,8 +142,10 @@ const keybinds: Keybind[] = [
callback: () => { callback: () => {
if (urlParams['template-overall']) if (urlParams['template-overall'])
window.location.href = document.URL.replace('template-overall=none/', ''); window.location.href = document.URL.replace('template-overall=none/', '');
else
window.location.href = `/template-overall=none/${document.URL.replace('https://www.nationstates.net/', '')}`;
else {
window.location.href = `/template-overall=none/
${document.URL.replace('https://www.nationstates.net/', '')}`;
}
}, },
modifiedCallback: null modifiedCallback: null
}, },
@@ -164,8 +175,10 @@ const keybinds: Keybind[] = [
functionName: 'regionajax', functionName: 'regionajax',
displayName: "Open Region Ajax2 Page", displayName: "Open Region Ajax2 Page",
callback: () => { callback: () => {
if (urlParams['region'])
window.location.href = `/page=ajax2/a=reports/view=region.${urlParams['region']}/filter=move+member+endo`;
if (urlParams['region']) {
window.location.href =
`/page=ajax2/a=reports/view=region.${urlParams['region']}/filter=move+member+endo`;
}
}, },
modifiedCallback: null modifiedCallback: null
} }


+ 8
- 7
src/settings.ts View File

@@ -31,7 +31,8 @@ async function addKeySetter(functionName: string, displayName?: string)
setKeyInput.addEventListener('click', async (e: MouseEvent): Promise<void> => setKeyInput.addEventListener('click', async (e: MouseEvent): Promise<void> =>
{ {
console.log(`Setting ${functionName}`); console.log(`Setting ${functionName}`);
const key: string = (document.querySelector(`#${functionName}-key`) as HTMLInputElement).value.toUpperCase();
const key: string = (document.querySelector(`#${functionName}-key`) as HTMLInputElement).value
.toUpperCase();
await setStorageValue(functionName, key); await setStorageValue(functionName, key);
}); });


@@ -39,16 +40,14 @@ async function addKeySetter(functionName: string, displayName?: string)
const td1: HTMLTableDataCellElement = document.createElement('td'); const td1: HTMLTableDataCellElement = document.createElement('td');
td1.innerHTML += `<label>${displayName}</label>`; td1.innerHTML += `<label>${displayName}</label>`;
const td2: HTMLTableDataCellElement = document.createElement('td'); const td2: HTMLTableDataCellElement = document.createElement('td');
td2.innerHTML += `<input type="text" id="${functionName}-key" value="${await getStorageValue(functionName) || '?'}">`;
td2.innerHTML +=
`<input type="text" id="${functionName}-key" value="${await getStorageValue(functionName) || '?'}">`;
const td3: HTMLTableDataCellElement = document.createElement('td'); const td3: HTMLTableDataCellElement = document.createElement('td');
td3.appendChild(setKeyInput); td3.appendChild(setKeyInput);
tr.appendChild(td1); tr.appendChild(td1);
tr.appendChild(td2); tr.appendChild(td2);
tr.appendChild(td3); tr.appendChild(td3);
document.querySelector('#keys').appendChild(tr); document.querySelector('#keys').appendChild(tr);
// This doesn't work apparently
/*document.querySelector('#keys').innerHTML +=
`<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>`;*/
} }


(async () => (async () =>
@@ -63,9 +62,11 @@ async function addKeySetter(functionName: string, displayName?: string)


// Other settings // Other settings
(document.querySelector('#jump-point') as HTMLInputElement).value = await getStorageValue('jp'); (document.querySelector('#jump-point') as HTMLInputElement).value = await getStorageValue('jp');
document.querySelector('#set-jump-point').addEventListener('click', async (e: MouseEvent): Promise<void> =>
document.querySelector('#set-jump-point')
.addEventListener('click', async (e: MouseEvent): Promise<void> =>
{ {
const jumpPoint: string = canonicalize((document.querySelector('#jump-point') as HTMLInputElement).value);
const jumpPoint: string =
canonicalize((document.querySelector('#jump-point') as HTMLInputElement).value);
await setStorageValue('jp', jumpPoint); await setStorageValue('jp', jumpPoint);
}); });
})(); })();

Loading…
Cancel
Save