mirror of
https://github.com/SilenceLurker/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 14:45:51 +00:00
Update renderer.js
This commit is contained in:
@@ -504,12 +504,12 @@ function renderHtmlInIframe(htmlContent, container, preElement) {
|
|||||||
iframe.srcdoc = full;
|
iframe.srcdoc = full;
|
||||||
}
|
}
|
||||||
wrapper.appendChild(iframe);
|
wrapper.appendChild(iframe);
|
||||||
preElement.classList.remove('xb-show');
|
preElement.classList.remove('amily2-show');
|
||||||
preElement.style.display = 'none';
|
preElement.style.display = 'none';
|
||||||
registerIframeMapping(iframe, wrapper);
|
registerIframeMapping(iframe, wrapper);
|
||||||
try { iframe.contentWindow?.postMessage({ type: 'probe' }, '*'); } catch (e) { }
|
try { iframe.contentWindow?.postMessage({ type: 'probe' }, '*'); } catch (e) { }
|
||||||
preElement.dataset.xbFinal = 'true';
|
preElement.dataset.amily2Final = 'true';
|
||||||
preElement.dataset.xbHash = originalHash;
|
preElement.dataset.amily2Hash = originalHash;
|
||||||
return iframe;
|
return iframe;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
@@ -525,18 +525,18 @@ function processCodeBlocks(messageElement) {
|
|||||||
const should = shouldRenderContentByBlock(codeBlock);
|
const should = shouldRenderContentByBlock(codeBlock);
|
||||||
const html = codeBlock.textContent || '';
|
const html = codeBlock.textContent || '';
|
||||||
const hash = djb2(html);
|
const hash = djb2(html);
|
||||||
const isFinal = preElement.dataset.xbFinal === 'true';
|
const isFinal = preElement.dataset.amily2Final === 'true';
|
||||||
const same = preElement.dataset.xbHash === hash;
|
const same = preElement.dataset.amily2Hash === hash;
|
||||||
if (isFinal && same) return;
|
if (isFinal && same) return;
|
||||||
if (should) {
|
if (should) {
|
||||||
renderHtmlInIframe(html, preElement.parentNode, preElement);
|
renderHtmlInIframe(html, preElement.parentNode, preElement);
|
||||||
} else {
|
} else {
|
||||||
preElement.classList.add('xb-show');
|
preElement.classList.add('amily2-show');
|
||||||
preElement.removeAttribute('data-xbfinal');
|
preElement.removeAttribute('data-amily2-final');
|
||||||
preElement.removeAttribute('data-xbhash');
|
preElement.removeAttribute('data-amily2-hash');
|
||||||
preElement.style.display = '';
|
preElement.style.display = '';
|
||||||
}
|
}
|
||||||
preElement.dataset.xiaobaixBound = 'true';
|
preElement.dataset.amily2Bound = 'true';
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[Amily2-Renderer] Error during processCodeBlocks:', err);
|
console.error('[Amily2-Renderer] Error during processCodeBlocks:', err);
|
||||||
@@ -550,6 +550,11 @@ function processMessageById(messageId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initializeRenderer() {
|
export function initializeRenderer() {
|
||||||
|
if (window.isXiaobaixEnabled) {
|
||||||
|
console.log('[Amily2-Renderer] 检测到 LittleWhiteBox 已激活,为避免冲突,Amily2 渲染器已禁用。');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const handleMessage = (data) => {
|
const handleMessage = (data) => {
|
||||||
const messageId = typeof data === 'object' ? data.messageId : data;
|
const messageId = typeof data === 'object' ? data.messageId : data;
|
||||||
if (messageId == null) return;
|
if (messageId == null) return;
|
||||||
@@ -592,7 +597,7 @@ export function clearAllIframes() {
|
|||||||
if (wrapper && wrapper.classList.contains('amily2-iframe-wrapper')) {
|
if (wrapper && wrapper.classList.contains('amily2-iframe-wrapper')) {
|
||||||
const preElement = wrapper.nextElementSibling;
|
const preElement = wrapper.nextElementSibling;
|
||||||
if (preElement && preElement.tagName === 'PRE') {
|
if (preElement && preElement.tagName === 'PRE') {
|
||||||
preElement.classList.add('xb-show');
|
preElement.classList.add('amily2-show');
|
||||||
preElement.style.display = '';
|
preElement.style.display = '';
|
||||||
}
|
}
|
||||||
wrapper.remove();
|
wrapper.remove();
|
||||||
|
|||||||
Reference in New Issue
Block a user