mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-08-08 11:38:42 +08:00
Fix: use correct selector #contact-widget-auto to hide Knocket widget
This commit is contained in:
+13
-2
@@ -8,22 +8,33 @@ script.
|
|||||||
const isChatBtn = !{theme.chat.rightside_button}
|
const isChatBtn = !{theme.chat.rightside_button}
|
||||||
const isChatHideShow = !{theme.chat.button_hide_show}
|
const isChatHideShow = !{theme.chat.button_hide_show}
|
||||||
|
|
||||||
const getWidget = () => document.querySelector('#knocket-widget, [id*="knocket"]')
|
const getWidget = () => document.getElementById('contact-widget-auto')
|
||||||
|
|
||||||
if (isChatBtn) {
|
if (isChatBtn) {
|
||||||
const hide = () => { const w = getWidget(); if (w) w.style.display = 'none' }
|
const hide = () => { const w = getWidget(); if (w) w.style.display = 'none' }
|
||||||
const show = () => { const w = getWidget(); if (w) w.style.display = '' }
|
const show = () => { const w = getWidget(); if (w) w.style.display = '' }
|
||||||
|
|
||||||
|
// Hide the native Knocket floating button
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
if (getWidget()) { hide(); observer.disconnect() }
|
||||||
|
})
|
||||||
|
observer.observe(document.body, { childList: true, subtree: true })
|
||||||
hide()
|
hide()
|
||||||
|
|
||||||
window.chatBtnFn = () => {
|
window.chatBtnFn = () => {
|
||||||
const w = getWidget()
|
const w = getWidget()
|
||||||
if (w && w.style.display === 'none') show()
|
if (!w) return
|
||||||
|
if (w.style.display === 'none') show()
|
||||||
else hide()
|
else hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('chat-btn').style.display = 'block'
|
document.getElementById('chat-btn').style.display = 'block'
|
||||||
} else if (isChatHideShow) {
|
} else if (isChatHideShow) {
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
if (getWidget()) observer.disconnect()
|
||||||
|
})
|
||||||
|
observer.observe(document.body, { childList: true, subtree: true })
|
||||||
|
|
||||||
window.chatBtn = {
|
window.chatBtn = {
|
||||||
hide: () => { const w = getWidget(); if (w) w.style.display = 'none' },
|
hide: () => { const w = getWidget(); if (w) w.style.display = 'none' },
|
||||||
show: () => { const w = getWidget(); if (w) w.style.display = '' }
|
show: () => { const w = getWidget(); if (w) w.style.display = '' }
|
||||||
|
|||||||
Reference in New Issue
Block a user