import { getChild } from '../floaty-children' ; import { getTaskCount , getTaskDelay , getTaskIntro , TaskCountResult , } from '../get-task-count' ; import { $ } from '../ui-object' ; type GetTaskBtn = ( container : UiObject ) => UiObject | null | undefined ; type GetTaskTitle = ( container : UiObject ) => string ; type GetTaskCount = ( container : UiObject ) => TaskCountResult | undefined ; type GetTaskIntro = ( container : UiObject ) => string | undefined ; type GetTaskDelay = ( container : UiObject ) => number ; interface TaskConfig { container : UiObject ; btn ? : UiObject | null | GetTaskBtn ; taskCount ? : TaskCountResult | GetTaskCount ; title ? : string | null | GetTaskTitle ; intro ? : string | GetTaskIntro ; delay ? : number | GetTaskDelay ; } class Task { private static defaultFns = { btn : ( container ) => { return $ ( container , /去完成/ ) ?? getChild ( container , 3 ) ; } , title : ( container ) => { return $ ( container , /.*\(\d+\/\d+.*/ ) ?. text ( ) ?? '' ; } , taskCount : ( container ) => { return getTaskCount ( container ) ; } , intro : ( container ) => { return getTaskIntro ( container ) ; } , delay : ( container ) => { return getTaskDelay ( container ) ; } , } ; public constructor ( public config ) { } public get title ( ) { return this . buildAttr ( 'title' ) ; } public get btn ( ) { return this . buildAttr ( 'btn' ) ; } public get taskCount ( ) { return this . buildAttr ( 'taskCount' ) ; } public get intro ( ) { return this . buildAttr ( 'intro' ) ; } public get delay ( ) : number { return this . buildAttr ( 'delay' ) ; } private buildAttr ( key ) ; private buildAttr ( key ) ; private buildAttr ( key ) ; private buildAttr ( key ) ; private buildAttr ( key ) ; private buildAttr ( key ) { const attrConfig = this . config [ key ] ; if ( attrConfig ) { if ( typeof attrConfig === 'function' ) { return attrConfig ( this . config . container ) ; } return attrConfig ; } return Task . defaultFns [ key ] ( this . config . container ) ; } } export { Task } ;