This commit is contained in:
xyf-mac
2021-11-04 21:01:33 +08:00
parent 50069b54dc
commit cff5edf263
9 changed files with 255 additions and 117 deletions

View File

@@ -13,7 +13,8 @@ export enum Msg {
Support = "game-support",// 游戏支持信息
MemoryInfo = "memory-info",//
TabsInfo = "tabs_info", // 当前页面信息
UrlChange = "url_change", // 网址发生变化
GetTabID = "GetTabID", // 获取页面ID
Test='Test',
SetProperty = "set-property", // 设置node属性
UpdateProperty = 'update-property', // 更新属性
}
@@ -45,7 +46,7 @@ export class PluginEvent {
this.source = source;
this.target = target;
this.msg = msg;
this.data = data || null;
this.data = data;
} else {
console.warn(`无效的target: ${target}`)
}

View File

@@ -2,12 +2,42 @@ export function injectScript(url: string) {
if (chrome && chrome.extension && chrome.extension.getURL) {
let content = chrome.extension.getURL(url)
console.log(`[cc-inspector]注入脚本:${content}`);
let script = document.createElement('script')
script.setAttribute('type', 'text/javascript')
script.setAttribute('src', content)
const script = document.createElement("script")
script.setAttribute("type", "text/javascript")
script.setAttribute("src", content)
script.onload = function () {
document.body.removeChild(script);
}
document.body.appendChild(script)
}
}
interface LogOptions {
data: any;
flag?: string;
color?: "red" | "blue";
}
export function log(options: LogOptions) {
const data: any = options.data;
const time = new Date().toLocaleString()
let log = ""
if (typeof data === "string") {
log = data;
} else if (typeof data === "object") {
log = JSON.stringify(data)
}
let str = "";
if (options.flag) {
str = `[${time}][${options.flag}]: ${log} `;
} else {
str = `[${time}]: ${log} `;
}
if (options.color) {
console.log(`%c${str}`, `color:${options.color};`)
} else {
console.log(str);
}
}