content-script.js
1 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
chrome.runtime.sendMessage({
type: "sessionStorage",
value: window.sessionStorage,
});
chrome.runtime.onMessage.addListener((res) => {
const { type } = res;
switch (type) {
case "setSessionStorage":
window.sessionStorage.setItem(res.key, res.value);
break;
case "removeSessionStorage":
window.sessionStorage.removeItem(res.key);
break;
case "reload":
window.location.reload();
break;
case "getLocalStorage":
chrome.runtime.sendMessage(window.sessionStorage);
break;
default:
return;
}
});
function injectCustomJs(jsPath) {
jsPath = jsPath || "inject.js";
var temp = document.createElement("script");
temp.setAttribute("type", "module");
temp.setAttribute("data-namespace", "qx-developer-tool-inject");
temp.src = chrome.extension.getURL(jsPath);
temp.onload = function () {
// 放在页面不好看,执行完后移除掉
// this.parentNode.removeChild(this);
};
document.body.appendChild(temp);
}
injectCustomJs();