Extract some dom-manipulations
This commit is contained in:
		| @@ -1,17 +1,19 @@ | ||||
| import { ActionController, registerAction } from './ActionController'; | ||||
| import { Args } from '../Common'; | ||||
| import { TryLaterError } from '../Errors'; | ||||
| import { GrabError, TryLaterError } from '../Errors'; | ||||
| import { Task } from '../Storage/TaskQueue'; | ||||
| import { clickUpgradeButton } from '../Page/BuildingPage'; | ||||
|  | ||||
| @registerAction | ||||
| export class UpgradeBuildingAction extends ActionController { | ||||
|     async run(args: Args, task: Task): Promise<any> { | ||||
|         const btn = jQuery('.upgradeButtonsContainer .section1 button.green.build'); | ||||
|  | ||||
|         if (btn.length !== 1) { | ||||
|         try { | ||||
|             clickUpgradeButton(); | ||||
|         } catch (e) { | ||||
|             if (e instanceof GrabError) { | ||||
|                 throw new TryLaterError(task.id, 15 * 60, 'No upgrade button, try later'); | ||||
|             } | ||||
|  | ||||
|         btn.trigger('click'); | ||||
|             throw e; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -7,7 +7,7 @@ import { BuildPage } from '../Page/BuildPage'; | ||||
| import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask'; | ||||
| import { grabResources } from '../Page/ResourcesBlock'; | ||||
| import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock'; | ||||
| import { onResourceSlotCtrlClick, showBuildingSlotIds, showFieldsSlotIds } from '../Page/SlotBlock'; | ||||
| import { onResourceSlotCtrlClick, showBuildingSlotIds, showResourceSlotIds } from '../Page/SlotBlock'; | ||||
|  | ||||
| export class Dashboard { | ||||
|     private readonly version: string; | ||||
| @@ -42,7 +42,7 @@ export class Dashboard { | ||||
|             .map(t => t.args.buildId); | ||||
|  | ||||
|         if (p.pathname === '/dorf1.php') { | ||||
|             showFieldsSlotIds(buildingsInQueue); | ||||
|             showResourceSlotIds(buildingsInQueue); | ||||
|             onResourceSlotCtrlClick(buildId => { | ||||
|                 this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId }); | ||||
|                 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> = []; | ||||
|     jQuery('.level.colorLayer').each((idx, el) => { | ||||
|         const buildId = getNumber(elClassId(jQuery(el).attr('class') || '', prefix)); | ||||
|         result.push({ | ||||
|             el, | ||||
|             buildId, | ||||
|         }); | ||||
|         result.push({ el, buildId }); | ||||
|     }); | ||||
|     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); | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user