Extract some dom-manipulations
This commit is contained in:
parent
a23872972e
commit
4dd11a60f7
@ -1,17 +1,19 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Common';
|
import { Args } from '../Common';
|
||||||
import { TryLaterError } from '../Errors';
|
import { GrabError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Storage/TaskQueue';
|
import { Task } from '../Storage/TaskQueue';
|
||||||
|
import { clickUpgradeButton } from '../Page/BuildingPage';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class UpgradeBuildingAction extends ActionController {
|
export class UpgradeBuildingAction extends ActionController {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const btn = jQuery('.upgradeButtonsContainer .section1 button.green.build');
|
try {
|
||||||
|
clickUpgradeButton();
|
||||||
if (btn.length !== 1) {
|
} catch (e) {
|
||||||
throw new TryLaterError(task.id, 15 * 60, 'No upgrade button, try later');
|
if (e instanceof GrabError) {
|
||||||
|
throw new TryLaterError(task.id, 15 * 60, 'No upgrade button, try later');
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
btn.trigger('click');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { BuildPage } from '../Page/BuildPage';
|
|||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
||||||
import { grabResources } from '../Page/ResourcesBlock';
|
import { grabResources } from '../Page/ResourcesBlock';
|
||||||
import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
|
import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
|
||||||
import { onResourceSlotCtrlClick, showBuildingSlotIds, showFieldsSlotIds } from '../Page/SlotBlock';
|
import { onResourceSlotCtrlClick, showBuildingSlotIds, showResourceSlotIds } from '../Page/SlotBlock';
|
||||||
|
|
||||||
export class Dashboard {
|
export class Dashboard {
|
||||||
private readonly version: string;
|
private readonly version: string;
|
||||||
@ -42,7 +42,7 @@ export class Dashboard {
|
|||||||
.map(t => t.args.buildId);
|
.map(t => t.args.buildId);
|
||||||
|
|
||||||
if (p.pathname === '/dorf1.php') {
|
if (p.pathname === '/dorf1.php') {
|
||||||
showFieldsSlotIds(buildingsInQueue);
|
showResourceSlotIds(buildingsInQueue);
|
||||||
onResourceSlotCtrlClick(buildId => {
|
onResourceSlotCtrlClick(buildId => {
|
||||||
this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId });
|
this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId });
|
||||||
const n = new Notification(`Building ${buildId} scheduled`);
|
const n = new Notification(`Building ${buildId} scheduled`);
|
||||||
|
9
src/Page/BuildingPage.ts
Normal file
9
src/Page/BuildingPage.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { GrabError } from '../Errors';
|
||||||
|
|
||||||
|
export function clickUpgradeButton() {
|
||||||
|
const btn = jQuery('.upgradeButtonsContainer .section1 button.green.build');
|
||||||
|
if (btn.length !== 1) {
|
||||||
|
throw new GrabError('No upgrade button, try later');
|
||||||
|
}
|
||||||
|
btn.trigger('click');
|
||||||
|
}
|
@ -9,10 +9,7 @@ function slotElements(prefix: string): Array<Slot> {
|
|||||||
const result: Array<Slot> = [];
|
const result: Array<Slot> = [];
|
||||||
jQuery('.level.colorLayer').each((idx, el) => {
|
jQuery('.level.colorLayer').each((idx, el) => {
|
||||||
const buildId = getNumber(elClassId(jQuery(el).attr('class') || '', prefix));
|
const buildId = getNumber(elClassId(jQuery(el).attr('class') || '', prefix));
|
||||||
result.push({
|
result.push({ el, buildId });
|
||||||
el,
|
|
||||||
buildId,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -35,7 +32,7 @@ function showSlotIds(prefix: string, buildingIds: number[]): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showFieldsSlotIds(buildingIds: number[]): void {
|
export function showResourceSlotIds(buildingIds: number[]): void {
|
||||||
showSlotIds('buildingSlot', buildingIds);
|
showSlotIds('buildingSlot', buildingIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user