App.vue
2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template>
<div class="inject-content" :style="style">{{ text }}</div>
</template>
<script setup>
import { onMounted } from "vue";
const DEVELOPER_MODE = window.sessionStorage.getItem("DEVELOPER_MODE") === "1";
const QX_DEBUG_APPS = JSON.parse(
window.sessionStorage.getItem("QX_DEBUG_APPS") || "[]"
);
const text = DEVELOPER_MODE && QX_DEBUG_APPS.length ? "调试中" : "开发模式";
const style = {
background:
"linear-gradient(to right, rgba(62, 142, 245, 0.6), rgb(62, 142, 245))",
width: "26px",
padding: "10px",
position: "absolute",
right: "0",
top: "calc(100vh / 2 - 50px)",
zIndex: 9999,
display: "flex",
alignItem: "center",
justifyContent: "center",
lineHeight: "18px",
color: "rgb(255, 255, 255)",
borderRadius: "6px 0px 0px 6px",
cursor: "default",
boxShadow: "rgba(62, 142, 245, 0.2) 0px 0px 5px",
};
function callback(mutationList, observer) {
mutationList.forEach((mutation) => {
switch (mutation.type) {
case "childList":
/* 从树上添加或移除一个或更多的子节点;参见 mutation.addedNodes 与
mutation.removedNodes */
const nodes = mutation.addedNodes;
nodes.forEach((node) => {
if (
node.innerText ===
"Disconnected from the devServer, trying to reconnect..."
) {
node.parentNode.removeChild(node);
}
});
break;
case "attributes":
/* mutation.target 中某节点的一个属性值被更改;该属性名称在 mutation.attributeName 中,
该属性之前的值为 mutation.oldValue */
break;
}
});
}
onMounted(() => {
var targetNode = document.body;
var observerOptions = {
childList: true, // 观察目标子节点的变化,是否有添加或者删除
attributes: true, // 观察属性变动
subtree: false, // 观察后代节点,默认为 false
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
});
</script>
<style>
</style>