|
@@ -69,4 +69,41 @@ export function getStringByHtml3(html) {
|
|
.replace(/>/g, ' ')
|
|
.replace(/>/g, ' ')
|
|
.replace(/<?img[^>]*>/g, '')
|
|
.replace(/<?img[^>]*>/g, '')
|
|
.replace(/<video[^>]*>.*?<\/video>/gi, '') : '';
|
|
.replace(/<video[^>]*>.*?<\/video>/gi, '') : '';
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// 在页面/组件的 onReady 或 mounted 生命周期中添加
|
|
|
|
+export function addClassToWebViewIframe() {
|
|
|
|
+ const targetSrc = "/hybrid/html/web/viewer.html"; // 替换为你的 WebView URL
|
|
|
|
+ const className = "custom-iframe-class"; // 要添加的类名
|
|
|
|
+
|
|
|
|
+ // 检查是否已存在目标 iframe
|
|
|
|
+ const existingIframe = Array.from(document.querySelectorAll('iframe')).find(
|
|
|
|
+ iframe => iframe.src.includes(targetSrc)
|
|
|
|
+ );
|
|
|
|
+ if (existingIframe) {
|
|
|
|
+ existingIframe.classList.add(className);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 使用 MutationObserver 监听新增 iframe
|
|
|
|
+ const observer = new MutationObserver(mutations => {
|
|
|
|
+ mutations.forEach(mutation => {
|
|
|
|
+ mutation.addedNodes.forEach(node => {
|
|
|
|
+ if (node.tagName === 'IFRAME' && node.src.includes(targetSrc)) {
|
|
|
|
+ node.classList.add(className);
|
|
|
|
+ observer.disconnect(); // 找到后停止监听
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 监听整个 body 的子元素变化
|
|
|
|
+ observer.observe(document.body, {
|
|
|
|
+ childList: true,
|
|
|
|
+ subtree: false
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 设置超时停止监听(防止内存泄漏)
|
|
|
|
+ setTimeout(() => observer.disconnect(), 5000);
|
|
|
|
+ }
|