Showing
3 changed files
with
49 additions
and
12 deletions
@@ -28,10 +28,11 @@ | @@ -28,10 +28,11 @@ | ||
28 | v-if="DEVELOPER_MODE == 1 && filterDebuggerApps.length" | 28 | v-if="DEVELOPER_MODE == 1 && filterDebuggerApps.length" |
29 | @click="end" | 29 | @click="end" |
30 | > | 30 | > |
31 | - <VideoPause | ||
32 | - style="width: 1em; height: 1em; margin-right: 8px" | ||
33 | - />关闭调试</el-button | ||
34 | - > | 31 | + <VideoPause style="width: 1em; height: 1em; margin-right: 8px" /> |
32 | + <el-tooltip content="关闭调试模式,会同步关闭开发者模式" placement=""> | ||
33 | + 关闭调试 | ||
34 | + </el-tooltip> | ||
35 | + </el-button> | ||
35 | <el-button v-else @click="start" | 36 | <el-button v-else @click="start" |
36 | ><VideoPlay style="width: 1em; height: 1em; margin-right: 8px" /> | 37 | ><VideoPlay style="width: 1em; height: 1em; margin-right: 8px" /> |
37 | 开启调试</el-button | 38 | 开启调试</el-button |
@@ -42,19 +43,19 @@ | @@ -42,19 +43,19 @@ | ||
42 | </template> | 43 | </template> |
43 | 44 | ||
44 | <script setup> | 45 | <script setup> |
45 | -import { reactive, ref, computed } from "vue"; | 46 | +import { reactive, ref, computed, watchEffect } from "vue"; |
46 | 47 | ||
47 | const { sessionStorage } = | 48 | const { sessionStorage } = |
48 | chrome.extension.getBackgroundPage().backgroundState || {}; | 49 | chrome.extension.getBackgroundPage().backgroundState || {}; |
49 | 50 | ||
50 | -const defaultApps = '[{"name":"","entry":""}]'; | 51 | +const defaultApps = [{ name: "", entry: "" }]; |
51 | 52 | ||
52 | const sessionDebuggerApps = JSON.parse( | 53 | const sessionDebuggerApps = JSON.parse( |
53 | - sessionStorage.QX_DEBUG_APPS || defaultApps | 54 | + sessionStorage.QX_DEBUG_APPS || JSON.stringify(defaultApps) |
54 | ); | 55 | ); |
55 | 56 | ||
56 | const QX_DEBUG_APPS = reactive( | 57 | const QX_DEBUG_APPS = reactive( |
57 | - JSON.parse(sessionDebuggerApps.length ? sessionDebuggerApps : defaultApps) | 58 | + sessionDebuggerApps.length ? sessionDebuggerApps : defaultApps |
58 | ); | 59 | ); |
59 | 60 | ||
60 | const filterDebuggerApps = computed(() => | 61 | const filterDebuggerApps = computed(() => |
@@ -3,11 +3,14 @@ | @@ -3,11 +3,14 @@ | ||
3 | </template> | 3 | </template> |
4 | 4 | ||
5 | <script setup> | 5 | <script setup> |
6 | +import { onMounted } from "vue"; | ||
7 | + | ||
6 | const DEVELOPER_MODE = window.sessionStorage.getItem("DEVELOPER_MODE") === "1"; | 8 | const DEVELOPER_MODE = window.sessionStorage.getItem("DEVELOPER_MODE") === "1"; |
7 | const QX_DEBUG_APPS = JSON.parse( | 9 | const QX_DEBUG_APPS = JSON.parse( |
8 | window.sessionStorage.getItem("QX_DEBUG_APPS") || "[]" | 10 | window.sessionStorage.getItem("QX_DEBUG_APPS") || "[]" |
9 | ); | 11 | ); |
10 | const text = DEVELOPER_MODE && QX_DEBUG_APPS.length ? "调试中" : "开发模式"; | 12 | const text = DEVELOPER_MODE && QX_DEBUG_APPS.length ? "调试中" : "开发模式"; |
13 | + | ||
11 | const style = { | 14 | const style = { |
12 | background: | 15 | background: |
13 | "linear-gradient(to right, rgba(62, 142, 245, 0.6), rgb(62, 142, 245))", | 16 | "linear-gradient(to right, rgba(62, 142, 245, 0.6), rgb(62, 142, 245))", |
@@ -26,6 +29,42 @@ const style = { | @@ -26,6 +29,42 @@ const style = { | ||
26 | cursor: "default", | 29 | cursor: "default", |
27 | boxShadow: "rgba(62, 142, 245, 0.2) 0px 0px 5px", | 30 | boxShadow: "rgba(62, 142, 245, 0.2) 0px 0px 5px", |
28 | }; | 31 | }; |
32 | + | ||
33 | +function callback(mutationList, observer) { | ||
34 | + mutationList.forEach((mutation) => { | ||
35 | + switch (mutation.type) { | ||
36 | + case "childList": | ||
37 | + /* 从树上添加或移除一个或更多的子节点;参见 mutation.addedNodes 与 | ||
38 | + mutation.removedNodes */ | ||
39 | + console.log("mutation", mutation); | ||
40 | + const nodes = mutation.addedNodes; | ||
41 | + nodes.forEach((node) => { | ||
42 | + if ( | ||
43 | + (node.innerText = | ||
44 | + "Disconnected from the devServer, trying to reconnect...") | ||
45 | + ) { | ||
46 | + node.parentNode.removeChild(node); | ||
47 | + } | ||
48 | + }); | ||
49 | + break; | ||
50 | + case "attributes": | ||
51 | + /* mutation.target 中某节点的一个属性值被更改;该属性名称在 mutation.attributeName 中, | ||
52 | + 该属性之前的值为 mutation.oldValue */ | ||
53 | + break; | ||
54 | + } | ||
55 | + }); | ||
56 | +} | ||
57 | + | ||
58 | +onMounted(() => { | ||
59 | + var targetNode = document.body; | ||
60 | + var observerOptions = { | ||
61 | + childList: true, // 观察目标子节点的变化,是否有添加或者删除 | ||
62 | + attributes: true, // 观察属性变动 | ||
63 | + subtree: false, // 观察后代节点,默认为 false | ||
64 | + }; | ||
65 | + var observer = new MutationObserver(callback); | ||
66 | + observer.observe(targetNode, observerOptions); | ||
67 | +}); | ||
29 | </script> | 68 | </script> |
30 | 69 | ||
31 | <style> | 70 | <style> |
@@ -2,11 +2,8 @@ import { createApp } from "vue"; | @@ -2,11 +2,8 @@ import { createApp } from "vue"; | ||
2 | import App from "./App.vue"; | 2 | import App from "./App.vue"; |
3 | 3 | ||
4 | const DEVELOPER_MODE = window.sessionStorage.getItem("DEVELOPER_MODE") === "1"; | 4 | const DEVELOPER_MODE = window.sessionStorage.getItem("DEVELOPER_MODE") === "1"; |
5 | -const QX_DEBUG_APPS = JSON.parse( | ||
6 | - window.sessionStorage.getItem("QX_DEBUG_APPS") || "[]" | ||
7 | -); | ||
8 | 5 | ||
9 | -if (DEVELOPER_MODE || QX_DEBUG_APPS.length) { | 6 | +if (DEVELOPER_MODE) { |
10 | const app = createApp(App); | 7 | const app = createApp(App); |
11 | 8 | ||
12 | const injectBody = document.createElement("div"); | 9 | const injectBody = document.createElement("div"); |