Add parse location utility
This commit is contained in:
		| @@ -1,5 +1,4 @@ | ||||
| import * as URLParse from 'url-parse'; | ||||
| import { getNumber, uniqId, waitForLoad } from './utils'; | ||||
| import { getNumber, parseLocation, uniqId, waitForLoad } from './utils'; | ||||
| import { Scheduler } from './Scheduler'; | ||||
| import { BuildPage } from './Page/BuildPage'; | ||||
| import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask'; | ||||
| @@ -38,12 +37,13 @@ export class ControlPanel { | ||||
|     async run() { | ||||
|         await waitForLoad(); | ||||
|  | ||||
|         const p = new URLParse(window.location.href, true); | ||||
|         const p = parseLocation(); | ||||
|         this.logger.log('PARSED LOCATION', p); | ||||
|  | ||||
|         const villageId = grabActiveVillageId(); | ||||
|  | ||||
|         this.grabbers.grab(); | ||||
|         setInterval(() => this.grabbers.grab(), 2000); | ||||
|  | ||||
|         const scheduler = this.scheduler; | ||||
|         const quickActions: QuickAction[] = []; | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import * as URLParse from 'url-parse'; | ||||
| import { parseLocation } from './utils'; | ||||
|  | ||||
| const SESSION_KEY = 'travian_automation_mode'; | ||||
| const SESSION_VALUE = 'command_execution'; | ||||
| @@ -14,7 +14,7 @@ export class ModeDetector { | ||||
|     } | ||||
|  | ||||
|     private isAutoByLocation(): boolean { | ||||
|         const p = new URLParse(window.location.href, true); | ||||
|         const p = parseLocation(); | ||||
|         return p.query[MODE_PARAMETER_NAME] !== undefined; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| import { Coordinates, Resources, Village, VillageList } from '../Game'; | ||||
| import { GrabError } from '../Errors'; | ||||
| import * as URLParse from 'url-parse'; | ||||
| import { getNumber } from '../utils'; | ||||
| import { getNumber, parseLocation } from '../utils'; | ||||
|  | ||||
| function getVillageListItems() { | ||||
|     const $elements = jQuery('#sidebarBoxVillagelist ul li a'); | ||||
| @@ -36,7 +35,7 @@ export function grabActiveVillageId(): number { | ||||
|  | ||||
| function grabVillageInfo($el): Village { | ||||
|     const href = $el.attr('href'); | ||||
|     const parsedHref = new URLParse(href || '', true); | ||||
|     const parsedHref = parseLocation(href || ''); | ||||
|     const id = getNumber(parsedHref.query.newdid); | ||||
|     const name = $el.find('.name').text(); | ||||
|     const active = $el.hasClass('active'); | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| import * as URLParse from 'url-parse'; | ||||
| import { StateGrabber } from './StateGrabber'; | ||||
| import { grabActiveVillageId, grabResourcesPerformance } from '../Page/VillageBlock'; | ||||
| import { VillageState } from './VillageState'; | ||||
| import { parseLocation } from '../utils'; | ||||
|  | ||||
| export class ResourcePerformanceGrabber extends StateGrabber { | ||||
|     grab(): void { | ||||
|         const p = new URLParse(window.location.href, true); | ||||
|         const p = parseLocation(); | ||||
|         if (p.pathname !== '/dorf1.php') { | ||||
|             return; | ||||
|         } | ||||
|   | ||||
| @@ -1,3 +1,5 @@ | ||||
| import * as URLParse from 'url-parse'; | ||||
|  | ||||
| export function sleep(ms: number) { | ||||
|     return new Promise(resolve => setTimeout(resolve, ms)); | ||||
| } | ||||
| @@ -88,6 +90,10 @@ export function getNumber(value: any, def: number = 0): number { | ||||
|     return converted === undefined ? def : converted; | ||||
| } | ||||
|  | ||||
| export function parseLocation(location?: string | undefined) { | ||||
|     return new URLParse(location || window.location.href, true); | ||||
| } | ||||
|  | ||||
| export function path(p: string, query: { [key: string]: string | number | undefined } = {}) { | ||||
|     let parts: string[] = []; | ||||
|     for (let k in query) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user