refactor
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Actions, Request } from "../common";
|
||||
import { sendMessage, ResponseChecker } from "./messaging";
|
||||
import { logger } from "./logger";
|
||||
import { logger } from "../common/logger";
|
||||
|
||||
/**
|
||||
* redirect tab to url.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { logger } from "./logger";
|
||||
import { logger } from "../common/logger";
|
||||
import { Actions } from "../common";
|
||||
import { messageSubscribers } from "./messaging";
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import { Task } from "./task";
|
||||
import { saveFile } from "./tools";
|
||||
import { createTab, getActiveTab, ping } from "./actions";
|
||||
import { ExtractResult } from "./result";
|
||||
import { logger } from "./logger";
|
||||
import { logger } from "../common/logger";
|
||||
import { caches } from "./caches";
|
||||
|
||||
export class Extractor {
|
||||
@ -12,6 +12,14 @@ export class Extractor {
|
||||
constructor(options?) {
|
||||
if (options) this._options = options;
|
||||
}
|
||||
static async ping(count: number = 1) {
|
||||
let tab = await getActiveTab(true) || await getActiveTab(false);
|
||||
let succ = await ping(tab, count);
|
||||
if (!succ) {
|
||||
logger.error('Cannot contact with active tab.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Save current state, in case we restore it later.
|
||||
*/
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Request, Actions, Response } from "../common";
|
||||
import { getTabByID } from "./actions";
|
||||
import { logger } from "./logger";
|
||||
import { logger } from "../common/logger";
|
||||
|
||||
|
||||
export type ResponseCheckerSync<T> = (r: Response<T>, err: chrome.runtime.LastError, count: number) => T;
|
||||
|
||||
@ -26,6 +26,7 @@ export class ExtractResult {
|
||||
}
|
||||
let line = lineCells.reduce(
|
||||
(lineText, cell, idx) => {
|
||||
cell = cell || "";
|
||||
cell = '"' + cell.trim().replace(/"/g, '""') + '"';
|
||||
return lineText + cell + (idx == lineCells.length - 1 ? "" : ",")
|
||||
}, "");
|
||||
|
||||
@ -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 "./logger";
|
||||
import { logger } from "../common/logger";
|
||||
|
||||
export class Task {
|
||||
private _data: { [key: string]: string[][] } = {};
|
||||
@ -87,7 +87,7 @@ export class Task {
|
||||
logger.info(`Watcher #${taskID} starts.`);
|
||||
let pm = this.makeOptionalTasks(sender.tab);
|
||||
return pm.then(
|
||||
() => extractTabData(sender.tab, this._itemsSelector, this._fieldSelectors, sender.tab.url, false)
|
||||
() => extractTabData(sender.tab, this._itemsSelector, this._fieldSelectors, sender.tab.url, true)
|
||||
).then(
|
||||
results => {
|
||||
if (results && results.length) {
|
||||
|
||||
@ -13,7 +13,7 @@ export class Logger {
|
||||
constructor(logLevel, notifyLevel) {
|
||||
if (logLevel) this._log_level = logLevel;
|
||||
if (notifyLevel) this._notify_level = notifyLevel;
|
||||
chrome.notifications.onClosed.addListener((id, byUser) => { this._notify_level = undefined });
|
||||
if (chrome.notifications) chrome.notifications.onClosed.addListener((id, byUser) => { this._notify_level = undefined });
|
||||
}
|
||||
get logLevel() {
|
||||
return this._log_level;
|
||||
Reference in New Issue
Block a user