调整评论显示
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
{{- with site.Params.comments.remark42 -}}
|
||||
<div id="remark42"></div>
|
||||
<script>
|
||||
var remark42_config = {
|
||||
var remark_config = {
|
||||
host: '{{ .host }}',
|
||||
site_id: '{{ .site_id }}',
|
||||
max_shown_comments: 15,
|
||||
theme: 'light',
|
||||
page_title: '{{ $.Title }}',
|
||||
locale: '{{ site.Language.Lang | default "zh" }}',
|
||||
locale: '{{ with site.Params.locale }}{{ if hasPrefix . "zh" }}zh{{ else }}{{ . }}{{ end }}{{ else }}zh{{ end }}',
|
||||
custom_css: '{{ site.BaseURL }}css/remark42.css',
|
||||
};
|
||||
</script>
|
||||
<script src="{{ .host }}/web/embed.js"></script>
|
||||
@@ -29,12 +30,12 @@
|
||||
if (frame && frame.contentWindow) {
|
||||
frame.contentWindow.postMessage(
|
||||
{ theme: getRemark42Theme() },
|
||||
remark42_config.host
|
||||
remark_config.host
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
remark42_config.theme = getRemark42Theme();
|
||||
remark_config.theme = getRemark42Theme();
|
||||
|
||||
window.addEventListener('message', function (e) {
|
||||
if (e.data && e.data.remark42) {
|
||||
@@ -52,6 +53,53 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Remove "Powered by Remark42" branding
|
||||
function removeBranding() {
|
||||
var frame = document.querySelector('iframe#remark42-frame');
|
||||
if (!frame || !frame.contentDocument) return;
|
||||
var doc = frame.contentDocument;
|
||||
// Try multiple known selectors for the branding element
|
||||
var selectors = [
|
||||
'a[href*="remark42"]',
|
||||
'a[href*="remark42.com"]',
|
||||
'.powered-by',
|
||||
'.remark42 .footer a',
|
||||
'footer a',
|
||||
];
|
||||
selectors.forEach(function (sel) {
|
||||
doc.querySelectorAll(sel).forEach(function (el) {
|
||||
el.style.display = 'none';
|
||||
});
|
||||
});
|
||||
// Also hide any parent container that only contains the branding
|
||||
doc.querySelectorAll('.powered-by, .footer').forEach(function (el) {
|
||||
if (el.children.length === 0 || el.textContent.trim().indexOf('Remark42') !== -1) {
|
||||
el.style.display = 'none';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Observe iframe content changes to catch dynamically rendered branding
|
||||
function observeBranding() {
|
||||
var frame = document.querySelector('iframe#remark42-frame');
|
||||
if (!frame || !frame.contentDocument) return;
|
||||
var observer = new MutationObserver(function () {
|
||||
removeBranding();
|
||||
});
|
||||
observer.observe(frame.contentDocument.body, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
// Run on iframe load and also poll briefly in case it loads fast
|
||||
var frame = document.querySelector('iframe#remark42-frame');
|
||||
if (frame) {
|
||||
frame.addEventListener('load', function () {
|
||||
removeBranding();
|
||||
observeBranding();
|
||||
});
|
||||
}
|
||||
setTimeout(removeBranding, 2000);
|
||||
setTimeout(removeBranding, 5000);
|
||||
})();
|
||||
</script>
|
||||
{{- else -}}
|
||||
|
||||
Reference in New Issue
Block a user