code optimize
This commit is contained in:
		| @ -1,6 +1,6 @@ | ||||
| import { Actions, Request } from "../common"; | ||||
| import { sendMessage } from "./messaging"; | ||||
| import { logger } from "./common"; | ||||
| import { logger } from "./logger"; | ||||
|  | ||||
| /** | ||||
|  * redirect tab to url. | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| import { logger } from "./common"; | ||||
| import { logger } from "./logger"; | ||||
| import { Actions } from "../common"; | ||||
| import { messageSubscribers } from "./messaging"; | ||||
|  | ||||
| @ -26,4 +26,6 @@ export class Caches { | ||||
|             } | ||||
|         }, 30000); | ||||
|     } | ||||
| } | ||||
| } | ||||
|  | ||||
| export const caches = new Caches(); | ||||
|  | ||||
| @ -1,6 +0,0 @@ | ||||
| import { Logger, LOGGER_LEVEL } from "./logger"; | ||||
| import { Caches } from "./caches"; | ||||
|  | ||||
| export const caches = new Caches(); | ||||
| export const logger = new Logger(LOGGER_LEVEL.DEBUG, LOGGER_LEVEL.DISABLED); | ||||
| export const URL_REG = /^\s*(https?):\/\//im; | ||||
| @ -1,8 +1,9 @@ | ||||
| import { Task } from "./task"; | ||||
| import { saveFile } from "./tools"; | ||||
| import { createTab, getActiveTab, ping } from "./actions"; | ||||
| import { logger, caches } from "./common"; | ||||
| import { ExtractResult } from "./result"; | ||||
| import { logger } from "./logger"; | ||||
| import { caches } from "./caches"; | ||||
|  | ||||
| export class Extractor { | ||||
|     private _tasks: Task[] = []; | ||||
|  | ||||
| @ -71,3 +71,5 @@ export class Logger { | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|  | ||||
| export const logger = new Logger(LOGGER_LEVEL.DEBUG, LOGGER_LEVEL.DISABLED); | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| import { Request, Actions } from "../common"; | ||||
| import { getTabByID } from "./actions"; | ||||
| import { logger } from "./common"; | ||||
| import { logger } from "./logger"; | ||||
|  | ||||
| /** | ||||
|  *  Sending a message to target tab repeatedly until the response is not undefined. | ||||
| @ -49,7 +49,13 @@ export function sendMessage<T>( | ||||
|                 let result: T = r; | ||||
|  | ||||
|                 if (dataChecker) { | ||||
|                     let pms = dataChecker(r, err, count); | ||||
|                     let pms: T | Promise<T>; | ||||
|                     try { | ||||
|                         pms = dataChecker(r, err, count); | ||||
|                     } catch (error) { | ||||
|                         reject(error); | ||||
|                         return; | ||||
|                     } | ||||
|                     // don't catch if it's not a Promise | ||||
|                     if (pms instanceof Promise) { | ||||
|                         let checkerError: any; | ||||
|  | ||||
| @ -4,7 +4,7 @@ import { testArgs, signitures } from "./signiture"; | ||||
| import { ExtractResult } from "./result"; | ||||
| import { messageSubscribers, ActionSubscriber } from "./messaging"; | ||||
| import { Actions } from "../common"; | ||||
| import { logger } from "./common"; | ||||
| import { logger } from "./logger"; | ||||
|  | ||||
| export class Task { | ||||
|     private _data: { [key: string]: string[][] } = {}; | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| import { URL_REG } from "./common"; | ||||
| import { ExtractResult } from "./result"; | ||||
|  | ||||
| const URL_REG = /^\s*(https?):\/\//im; | ||||
|  | ||||
| export function parseUrls(...args) { | ||||
|     if (!args.length) return []; | ||||
|     let arg = args.shift(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user