Pārlūkot izejas kodu

adjusted line lengths to be below maximum recommended line length

master
Haku pirms 3 gadiem
vecāks
revīzija
0abb5d8b09
2 mainītis faili ar 34 papildinājumiem un 20 dzēšanām
  1. +26
    -13
      src/main.ts
  2. +8
    -7
      src/settings.ts

+ 26
- 13
src/main.ts Parādīt failu

@@ -11,7 +11,8 @@ const keybinds: Keybind[] = [
functionName: 'move',
displayName: null,
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)
moveButton.click();
},
@@ -21,7 +22,8 @@ const keybinds: Keybind[] = [
functionName: 'endorse',
displayName: null,
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)
endorseButton.click();
},
@@ -31,7 +33,8 @@ const keybinds: Keybind[] = [
}
else if (urlParams['nation']) {
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))
endorseButton.click();
else if (nationsToEndorse.indexOf(urlParams['nation']) !== -1) {
@@ -57,7 +60,8 @@ const keybinds: Keybind[] = [
functionName: 'dossier',
displayName: null,
callback: () => {
const dossierButton: HTMLButtonElement = document.querySelector('button[value=add]') as HTMLButtonElement;
const dossierButton: HTMLButtonElement =
document.querySelector('button[value=add]') as HTMLButtonElement;
if (dossierButton)
dossierButton.click();
},
@@ -67,7 +71,8 @@ const keybinds: Keybind[] = [
}
else if (urlParams['nation']) {
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))
dossierButton.click();
else {
@@ -81,7 +86,8 @@ const keybinds: Keybind[] = [
}
else if (urlParams['page'] === 'dossier') {
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];
if (!nextNation)
return;
@@ -95,7 +101,8 @@ const keybinds: Keybind[] = [
functionName: 'backtojp',
displayName: "Move Back to Jump Point",
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');
if ((urlParams['region'] === jumpPoint) && moveButton)
moveButton.click();
@@ -108,11 +115,13 @@ const keybinds: Keybind[] = [
functionName: 'endodel',
displayName: "Endorse WA Delegate",
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'])
delegate.click();
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)
endorseButton.click();
}
@@ -133,8 +142,10 @@ const keybinds: Keybind[] = [
callback: () => {
if (urlParams['template-overall'])
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
},
@@ -164,8 +175,10 @@ const keybinds: Keybind[] = [
functionName: 'regionajax',
displayName: "Open Region Ajax2 Page",
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
}


+ 8
- 7
src/settings.ts Parādīt failu

@@ -31,7 +31,8 @@ async function addKeySetter(functionName: string, displayName?: string)
setKeyInput.addEventListener('click', async (e: MouseEvent): Promise<void> =>
{
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);
});

@@ -39,16 +40,14 @@ async function addKeySetter(functionName: string, displayName?: string)
const td1: HTMLTableDataCellElement = document.createElement('td');
td1.innerHTML += `<label>${displayName}</label>`;
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');
td3.appendChild(setKeyInput);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
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 () =>
@@ -63,9 +62,11 @@ async function addKeySetter(functionName: string, displayName?: string)

// Other settings
(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);
});
})();

Notiek ielāde…
Atcelt
Saglabāt