diff --git a/source/package.json b/source/package.json index f8c8350..8af876d 100644 --- a/source/package.json +++ b/source/package.json @@ -5,8 +5,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "build-watch": "vue-cli-service build --watch", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "build-watch": "vue-cli-service build --watch" }, "dependencies": { "@types/fs-extra": "^9.0.9", @@ -37,8 +37,8 @@ "lint-staged": "^9.5.0", "prettier": "^2.2.1", "typescript": "~4.1.5", - "vue-template-compiler": "^2.6.11", - "vue-cli-plugin-browser-extension": "latest" + "vue-cli-plugin-browser-extension": "latest", + "vue-template-compiler": "^2.6.11" }, "browserslist": [ "> 1%", diff --git a/source/plugins/copy.js b/source/plugins/copy.js new file mode 100644 index 0000000..071e262 --- /dev/null +++ b/source/plugins/copy.js @@ -0,0 +1,31 @@ +const Fs = require("fs"); +const Path = require("path"); +const FsExtra = require("fs-extra"); + +class Copy { + constructor(options) { + this.options = options; + } + + apply(compiler) { + compiler.plugin("done", (compilation, callback) => { + const cfg = this.options; + if (cfg && cfg.length > 0) { + cfg.forEach(({src, dest}) => { + let fullSrc = Path.join(compilation.compilation.options.context, src); + if (Fs.existsSync(fullSrc)) { + let distPath = compilation.compilation.options.output.path; + let outFile = Path.join(distPath, dest); + FsExtra.ensureFileSync(outFile); + FsExtra.copyFileSync(fullSrc, outFile); + } else { + console.error(`manifest文件不存在:${src}`); + } + }); + } + }); + + } +} + +module.exports = Copy; diff --git a/source/src/content.ts b/source/src/content.ts index 9e28817..5a2162a 100644 --- a/source/src/content.ts +++ b/source/src/content.ts @@ -1 +1,58 @@ console.log('content code') +// 具有操作dom的能力 +// 加载其他脚本 +// content.js 和原始界面共享DOM,但是不共享js,要想访问页面js,只能通过注入的方式 +import * as PluginMsg from './core/plugin-msg' + +function injectScriptToPage(url) { + 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) + script.onload = function () { + // 注入脚本执行完后移除掉 + this.parentNode.removeChild(this); + } + document.body.appendChild(script) +} +debugger +injectScriptToPage("js/inject.js"); + +// 和background.js保持长连接通讯 +let conn = chrome.runtime.connect({name: PluginMsg.Page.Content}) +// conn.postMessage('test'); +conn.onMessage.addListener(function (data) { + // 将background.js的消息返回到injection.js + window.postMessage(data, "*"); +}) +// 接受来自inject.js的消息数据,然后中转到background.js +window.addEventListener('message', function (event) { + let data = event.data; + if (data.data.log) { + } + console.log(`%c[content] ${JSON.stringify(data)}`, "color:#BD4E19"); + chrome.runtime.sendMessage(data); +}, false); + + +let gameCanvas = document.querySelector("#GameCanvas"); +if (gameCanvas) { + // console.log('find GameCanvas element'); + // gameCanvas.addEventListener('click', function () { + // console.log("click canvas"); + // }); + // gameCanvas.style.display = 'none'; +} else { + // console.log("can't find GameCanvas element"); + // 和background.js保持短连接通讯 + chrome.runtime.sendMessage({ + msg: PluginMsg.Msg.Support, + data: { + support: false, + msg: "未发现GameCanvas,不支持调试游戏!" + } + }, function (data) { + // console.log(data) + }); +} diff --git a/source/src/core/content.js b/source/src/core/content.js deleted file mode 100644 index a7a2d77..0000000 --- a/source/src/core/content.js +++ /dev/null @@ -1,57 +0,0 @@ -// 具有操作dom的能力 -// 加载其他脚本 -// content.js 和原始界面共享DOM,但是不共享js,要想访问页面js,只能通过注入的方式 -const PluginMsg = require("../core/plugin-msg"); - -function injectScriptToPage(url) { - 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) - script.onload = function () { - // 注入脚本执行完后移除掉 - this.parentNode.removeChild(this); - } - document.body.appendChild(script) -} - -injectScriptToPage("js/inject.js"); - -// 和background.js保持长连接通讯 -let conn = chrome.runtime.connect({name: PluginMsg.Page.Content}) -// conn.postMessage('test'); -conn.onMessage.addListener(function (data) { - // 将background.js的消息返回到injection.js - window.postMessage(data, "*"); -}) -// 接受来自inject.js的消息数据,然后中转到background.js -window.addEventListener('message', function (event) { - let data = event.data; - if (data.data.log) { - } - console.log(`%c[content] ${JSON.stringify(data)}`, "color:#BD4E19"); - chrome.runtime.sendMessage(data); -}, false); - - -let gameCanvas = document.querySelector("#GameCanvas"); -if (gameCanvas) { - // console.log('find GameCanvas element'); - // gameCanvas.addEventListener('click', function () { - // console.log("click canvas"); - // }); - // gameCanvas.style.display = 'none'; -} else { - // console.log("can't find GameCanvas element"); - // 和background.js保持短连接通讯 - chrome.runtime.sendMessage({ - msg: PluginMsg.Msg.Support, - data: { - support: false, - msg: "未发现GameCanvas,不支持调试游戏!" - } - }, function (data) { - // console.log(data) - }); -} diff --git a/source/src/core/event-mgr.js b/source/src/core/event-mgr.js deleted file mode 100644 index 1265300..0000000 --- a/source/src/core/event-mgr.js +++ /dev/null @@ -1,7 +0,0 @@ -// const PluginMsg = require("./plugin-msg"); -// module.exports = { -// id: "event-mgr", -// testInit(name) { -// chrome.runtime.connect({name: name}) -// } -// } diff --git a/source/src/core/event.js b/source/src/core/event.js deleted file mode 100644 index 998067b..0000000 --- a/source/src/core/event.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - id: "event-id", -} diff --git a/source/src/core/page.ejs b/source/src/core/page.ejs deleted file mode 100644 index 5497d40..0000000 --- a/source/src/core/page.ejs +++ /dev/null @@ -1,10 +0,0 @@ - - -
- -- - 隐藏节点 -
- -- - 显示节点 -
-