Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 19cb4c2

Browse files
committed
取消油猴压缩
1 parent 5866a24 commit 19cb4c2

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "node_modules/.bin/jest",
88
"build": "node_modules/.bin/webpack --mode production --config webpack.config.js",
9-
"tampermonkey": "node_modules/.bin/webpack --mode production --config webpack.tampermonkey.js",
9+
"tampermonkey": "node_modules/.bin/webpack --mode development --config webpack.tampermonkey.js",
1010
"dev": "node_modules/.bin/webpack --mode development --config webpack.dev.js",
1111
"pack": "node_modules/.bin/tsc src/internal/pack-crx.ts && node src/internal/pack-crx.js",
1212
"docs:dev": "node_modules/.bin/vuepress dev docs",

src/internal/utils/log.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export class ConsoleLog implements Logger {
5050

5151
export class PageLog implements Logger {
5252
protected el: HTMLElement;
53+
54+
protected getNowTime(): string {
55+
let time = new Date();
56+
return time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
57+
}
58+
5359
constructor() {
5460
this.el = undefined;
5561
window.addEventListener("load", () => {
@@ -59,17 +65,22 @@ export class PageLog implements Logger {
5965
document.body.appendChild(div);
6066
this.el = div.querySelector(".tools-notice-content");
6167
(<HTMLButtonElement>div.querySelector("button.close")).onclick = () => {
62-
this.el=undefined;
68+
this.el = undefined;
6369
div.remove();
6470
};
6571
});
6672
}
73+
6774
public Trace(...args: any): Logger {
75+
console.trace("[trace", this.getNowTime(), "]", ...args);
6876
return this;
6977
}
78+
7079
public Debug(...args: any): Logger {
80+
console.info("[debug", this.getNowTime(), "]", ...args);
7181
return this;
7282
}
83+
7384
public Info(...args: any): Logger {
7485
let text = "";
7586
for (let i = 0; i < args.length; i++) {

src/internal/utils/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ export function Injected(doc: Document, source: string): Element {
137137
return temp;
138138
}
139139

140+
/**
141+
* 通过源码注入js资源
142+
* @param doc
143+
* @param url
144+
* @constructor
145+
*/
146+
export function InjectedBySrc(doc: Document, source: string): Element {
147+
let temp = doc.createElement('script');
148+
temp.setAttribute('type', 'text/javascript');
149+
temp.src = source;
150+
temp.className = "injected-js";
151+
doc.documentElement.appendChild(temp);
152+
return temp;
153+
}
154+
140155
export function syncGetChromeStorageLocal(key: string): Promise<any> {
141156
return new Promise<any>(resolve => (chrome.storage.local.get(key, (value) => {
142157
resolve(<any>value[<string>key]);

src/start.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NewChromeServerMessage } from "@App/internal/utils/message";
2-
import { HttpUtils, Injected, get, syncGetChromeStorageLocal } from "@App/internal/utils/utils";
2+
import { HttpUtils, InjectedBySrc } from "@App/internal/utils/utils";
33
import { Application, Content, Launcher } from "@App/internal/application";
44
import { ChromeConfigItems, NewBackendConfig } from "@App/internal/utils/config";
55
import { ConsoleLog } from "./internal/utils/log";
@@ -9,9 +9,7 @@ class start implements Launcher {
99
public async start() {
1010
//调试环境注入脚本
1111
if (Application.App.debug) {
12-
get(chrome.extension.getURL('src/mooc.js'), function (source: string) {
13-
Injected(document, source);
14-
});
12+
InjectedBySrc(document, chrome.extension.getURL('src/mooc.js'));
1513
}
1614
//注入config
1715
let configKeyList: string[] = new Array();

0 commit comments

Comments
 (0)