This commit is contained in:
xu_yanfeng 2024-01-09 18:11:40 +08:00
parent 47744fd87e
commit 3b9726f284
4 changed files with 9 additions and 13 deletions

View File

@ -1,7 +1,7 @@
export function injectScript(url: string) {
if (chrome && chrome.extension && chrome.extension.getURL) {
let content = chrome.extension.getURL(url)
console.log(`[cc-inspector]注入脚本:${content}`);
console.log(`[cc-inspector] inject script: ${content}`);
const script = document.createElement("script")
script.setAttribute("type", "text/javascript")
script.setAttribute("src", content)
@ -12,7 +12,6 @@ export function injectScript(url: string) {
}
}
interface LogOptions {
data: any;
flag?: string;

View File

@ -1,9 +1,9 @@
// content.js 和原始界面共享DOM具有操作dom的能力
// 但是不共享js,要想访问页面js,只能通过注入的方式
import {injectScript} from "../core/util";
import {Msg, Page, PluginEvent} from "../core/types";
injectScript("js/inject.js");
import { injectScript } from "../core/util";
import { Msg, Page, PluginEvent } from "../core/types";
import { ChromeConst } from "cc-plugin/src/chrome/const";
injectScript(ChromeConst.script.inject);
class Content {
private connect: chrome.runtime.Port | null = null;
@ -22,7 +22,7 @@ class Content {
// 和background.js保持长连接通讯background和content的交互也要通过这个链接进行通讯
private connectToBackground() {
this.connect = chrome.runtime.connect({name: Page.Content})
this.connect = chrome.runtime.connect({ name: Page.Content })
this.connect.onMessage.addListener((data: PluginEvent, sender) => {
if (PluginEvent.check(data, Page.Background, Page.Content)) {
// console.log(`%c[Connect-Message] ${JSON.stringify(data)}`, "color:green;")
@ -39,7 +39,7 @@ class Content {
}
}
async run() {
run() {
this.connectToBackground();
this.checkGame();
}

View File

@ -4,6 +4,7 @@ import CCP from "cc-plugin/src/ccp/entry-render";
import pluginConfig from "../../../cc-plugin.config";
import ccui from "@xuyanfeng/cc-ui";
import "@xuyanfeng/cc-ui/dist/ccui.css";
import "@xuyanfeng/cc-ui/iconfont/use.css";
import "@xuyanfeng/cc-ui/iconfont/iconfont.css";
export default CCP.init(pluginConfig, {

View File

@ -4,7 +4,7 @@
<div class="name">{{ title }}</div>
<div style="flex: 1"></div>
<CCButton @click="onClickOptions">
<i class="iconfont icon_setting"></i>
<i class="iconfont icon_settings"></i>
</CCButton>
</div>
@ -93,10 +93,6 @@ export default defineComponent({
</script>
<style scoped lang="less">
.popup {
widows: 10px;
height: 10px;
background-color: rebeccapurple;
width: 300px;
display: flex;
flex-direction: column;