fix(theme): Adjust Cusdis widget scrollbar and background to match Stack theme (#1204)
* fix: adjust cusdis scrollbar styling and background for stack theme * feat: dynamically set cusdis background color --------- Co-authored-by: Jimmy <jimmy@cai.im>
This commit is contained in:
@@ -1,20 +1,26 @@
|
|||||||
{{- $host := default "https://cusdis.com" .Site.Params.comments.cusdis.host -}}
|
{{- $host := default "https://cusdis.com" .Site.Params.comments.cusdis.host -}}
|
||||||
<div id="cusdis_thread"
|
<div id="cusdis_thread" data-host="{{ $host }}" data-app-id="{{ .Site.Params.comments.cusdis.id }}"
|
||||||
data-host="{{ $host }}"
|
data-page-id="{{ .File.UniqueID }}" data-page-url="{{ .Permalink }}" data-page-title="{{ .Title }}"></div>
|
||||||
data-app-id="{{ .Site.Params.comments.cusdis.id }}"
|
|
||||||
data-page-id="{{ .File.UniqueID }}"
|
|
||||||
data-page-url="{{ .Permalink }}"
|
|
||||||
data-page-title="{{ .Title }}"></div>
|
|
||||||
<script async defer src="{{ $host }}/js/cusdis.es.js"></script>
|
<script async defer src="{{ $host }}/js/cusdis.es.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function setCusdisTheme(theme) {
|
function setCusdisTheme(theme) {
|
||||||
let cusdis = document.querySelector('#cusdis_thread iframe');
|
let cusdis = document.querySelector('#cusdis_thread iframe');
|
||||||
if (cusdis) {
|
if (cusdis) {
|
||||||
window.CUSDIS.setTheme(theme)
|
window.CUSDIS.setTheme(theme);
|
||||||
|
cusdis.contentWindow.document.body.style.backgroundColor = window.getComputedStyle(document.body).backgroundColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window.addEventListener('load', function () {
|
||||||
|
let iframe = document.querySelector("#cusdis_thread iframe");
|
||||||
|
if (iframe) {
|
||||||
|
let observer = new MutationObserver(() => {
|
||||||
|
let scrollHeight = iframe.contentWindow.document.body.scrollHeight;
|
||||||
|
iframe.style.height = scrollHeight + "px";
|
||||||
|
});
|
||||||
|
observer.observe(iframe.contentWindow.document.body, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
window.addEventListener('onColorSchemeChange', (e) => {
|
window.addEventListener('onColorSchemeChange', (e) => {
|
||||||
setCusdisTheme(e.detail)
|
setCusdisTheme(e.detail)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user