This commit is contained in:
zhu
2026-04-30 11:17:16 +08:00
parent 08a6a69bd6
commit 7ca9dabaf9
6 changed files with 192 additions and 132 deletions

View File

@@ -3,22 +3,24 @@ import App from './App.vue';
/** 将内容脚本应用挂载到页面中。 */
function mountApp() {
if (document.getElementById('dianshan-crx-root')) {
return;
}
if (document.getElementById('dianshan-crx-root')) {
return;
}
const container = document.createElement('div');
container.id = 'dianshan-crx-root';
const appRoot = document.createElement('div');
/** 内容脚本在宿主页面中的根容器,用于避免污染业务页面结构。 */
const container = document.createElement('div');
container.id = 'dianshan-crx-root';
/** Vue 应用实际挂载的节点。 */
const appRoot = document.createElement('div');
container.appendChild(appRoot);
document.body.appendChild(container);
container.appendChild(appRoot);
document.body.appendChild(container);
createApp(App).mount(appRoot);
createApp(App).mount(appRoot);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', mountApp, { once: true });
document.addEventListener('DOMContentLoaded', mountApp, { once: true });
} else {
mountApp();
mountApp();
}