feat: 移除 pangu.js

feat: js 加载完成才显示聊天按钮
This commit is contained in:
myw
2024-11-15 14:53:40 +08:00
parent 91c8c5cd4b
commit b7771e5938
12 changed files with 96 additions and 143 deletions

View File

@@ -101,7 +101,7 @@ npm i hexo-theme-butterfly
- [x] Chart.js - [x] Chart.js
- [x] Justified Gallery - [x] Justified Gallery
- [x] Lazyload images - [x] Lazyload images
- [x] Instantpage/Pangu/Snackbar notification toast/PWA...... - [x] Instantpage/Snackbar notification toast/PWA......
## ✨ Contributors ## ✨ Contributors

View File

@@ -101,7 +101,7 @@ theme: butterfly
- [x] Chart.js 圖表顯示 - [x] Chart.js 圖表顯示
- [x] 照片牆 - [x] 照片牆
- [x] 圖片懶加載 - [x] 圖片懶加載
- [x] Instantpage/Pangu/Snackbar彈窗/PWA...... - [x] Instantpage/Snackbar彈窗/PWA......
## ✨ 貢獻者 ## ✨ 貢獻者

View File

@@ -983,13 +983,6 @@ snackbar:
# https://instant.page/ # https://instant.page/
instantpage: false instantpage: false
# Pangu - Insert a space between Chinese character and English character
# https://github.com/vinta/pangu.js
pangu:
enable: false
# Specify the field to use pangu (site or post)
field: site
# Lazyload # Lazyload
# https://github.com/verlok/vanilla-lazyload # https://github.com/verlok/vanilla-lazyload
lazyload: lazyload:
@@ -1092,7 +1085,6 @@ CDN:
# medium_zoom: # medium_zoom:
# mermaid: # mermaid:
# meting_js: # meting_js:
# pangu:
# prismjs_autoloader: # prismjs_autoloader:
# prismjs_js: # prismjs_js:
# prismjs_lineNumber_js: # prismjs_lineNumber_js:

View File

@@ -17,9 +17,6 @@ div
if theme.snackbar.enable if theme.snackbar.enable
script(src=url_for(theme.asset.snackbar)) script(src=url_for(theme.asset.snackbar))
if theme.pangu.enable
!= partial("includes/third-party/pangu.pug", {}, { cache: true })
.js-pjax .js-pjax
if needLoadCountJs if needLoadCountJs
!= partial("includes/third-party/card-post-count/index", {}, { cache: true }) != partial("includes/third-party/card-post-count/index", {}, { cache: true })

View File

@@ -23,7 +23,7 @@ mixin rightsideItem(array)
i.fas.fa-list-ul i.fas.fa-list-ul
when 'chat' when 'chat'
if chat.rightside_button && chat.use if chat.rightside_button && chat.use
button#chat-btn(type="button" title=_p("rightside.chat")) button#chat-btn(type="button" title=_p("rightside.chat") style="display:none")
i.fas.fa-message i.fas.fa-message
when 'comment' when 'comment'
if commentsJsLoad if commentsJsLoad

View File

@@ -1,42 +1,38 @@
//- https://chatra.io/help/api/ //- https://chatra.io/help/api/
script. script.
(() => { (() => {
const isChatBtn = !{theme.chat.rightside_button} window.ChatraID = '#{theme.chatra.id}'
const isChatHideShow = !{theme.chat.button_hide_show} window.Chatra = window.Chatra || function() {
(window.Chatra.q = window.Chatra.q || []).push(arguments)
if (isChatBtn) {
const close = () => {
Chatra('minimizeWidget')
Chatra('hide')
}
const open = () => {
Chatra('openChat', true)
Chatra('show')
}
window.ChatraSetup = { startHidden: true }
window.chatBtnFn = () => {
document.getElementById('chatra').classList.contains('chatra--expanded') ? close() : open()
}
} else if (isChatHideShow) {
window.chatBtn = {
hide: () => Chatra('hide'),
show: () => Chatra('show')
}
} }
(function(d, w, c) { btf.getScript('https://call.chatra.io/chatra.js').then(() => {
w.ChatraID = '#{theme.chatra.id}' const isChatBtn = !{theme.chat.rightside_button}
var s = d.createElement('script') const isChatHideShow = !{theme.chat.button_hide_show}
w[c] = w[c] || function() {
(w[c].q = w[c].q || []).push(arguments) if (isChatBtn) {
const close = () => {
Chatra('minimizeWidget')
Chatra('hide')
}
const open = () => {
Chatra('openChat', true)
Chatra('show')
}
window.ChatraSetup = { startHidden: true }
window.chatBtnFn = () => document.getElementById('chatra').classList.contains('chatra--expanded') ? close() : open()
document.getElementById('chat-btn').style.display = 'block'
} else if (isChatHideShow) {
window.chatBtn = {
hide: () => Chatra('hide'),
show: () => Chatra('show')
}
} }
s.async = true })
s.src = 'https://call.chatra.io/chatra.js'
if (d.head) d.head.appendChild(s)
})(document, window, 'Chatra')
})() })()

View File

@@ -1,37 +1,32 @@
script. script.
(() => { (() => {
window.$crisp = []; window.$crisp = ['safe', true]
window.CRISP_WEBSITE_ID = "!{theme.crisp.website_id}"; window.CRISP_WEBSITE_ID = "!{theme.crisp.website_id}"
(function () {
d = document;
s = d.createElement("script");
s.src = "https://client.crisp.chat/l.js";
s.async = 1;
d.getElementsByTagName("head")[0].appendChild(s);
})();
$crisp.push(["safe", true])
const isChatBtn = !{theme.chat.rightside_button} btf.getScript('https://client.crisp.chat/l.js').then(() => {
const isChatHideShow = !{theme.chat.button_hide_show} const isChatBtn = !{theme.chat.rightside_button}
const isChatHideShow = !{theme.chat.button_hide_show}
if (isChatBtn) { if (isChatBtn) {
const open = () => { const open = () => {
$crisp.push(["do", "chat:show"]) $crisp.push(["do", "chat:show"])
$crisp.push(["do", "chat:open"]) $crisp.push(["do", "chat:open"])
}
const close = () => $crisp.push(["do", "chat:hide"])
close()
$crisp.push(["on", "chat:closed", close])
window.chatBtnFn = () => $crisp.is("chat:visible") ? close() : open()
document.getElementById('chat-btn').style.display = 'block'
} else if (isChatHideShow) {
window.chatBtn = {
hide: () => $crisp.push(["do", "chat:hide"]),
show: () => $crisp.push(["do", "chat:show"])
}
} }
})
const close = () => $crisp.push(["do", "chat:hide"])
close()
$crisp.push(["on", "chat:closed", close])
window.chatBtnFn = () => $crisp.is("chat:visible") ? close() : open()
} else if (isChatHideShow) {
window.chatBtn = {
hide: () => $crisp.push(["do", "chat:hide"]),
show: () => $crisp.push(["do", "chat:show"])
}
}
})() })()

View File

@@ -1,41 +1,45 @@
script(src=`//code.tidio.co/${theme.tidio.public_key}.js` async)
script. script.
(() => { (() => {
const isChatBtn = !{theme.chat.rightside_button} btf.getScript('//code.tidio.co/!{theme.tidio.public_key}.js').then(() => {
const isChatHideShow = !{theme.chat.button_hide_show} const isChatBtn = !{theme.chat.rightside_button}
const isChatHideShow = !{theme.chat.button_hide_show}
if (isChatBtn) { if (isChatBtn) {
let isShow = false let isShow = false
const close = () => { const close = () => {
window.tidioChatApi.hide() window.tidioChatApi.hide()
isShow = false isShow = false
} }
const open = () => { const open = () => {
window.tidioChatApi.open() window.tidioChatApi.open()
window.tidioChatApi.show() window.tidioChatApi.show()
isShow = true isShow = true
} }
const onTidioChatApiReady = () => { const onTidioChatApiReady = () => {
window.tidioChatApi.hide() window.tidioChatApi.hide()
window.tidioChatApi.on("close", close) window.tidioChatApi.on("close", close)
} }
if (window.tidioChatApi) { if (window.tidioChatApi) {
window.tidioChatApi.on("ready", onTidioChatApiReady) window.tidioChatApi.on("ready", onTidioChatApiReady)
} else { } else {
document.addEventListener("tidioChat-ready", onTidioChatApiReady) document.addEventListener("tidioChat-ready", onTidioChatApiReady)
} }
window.chatBtnFn = () => { window.chatBtnFn = () => {
if (!window.tidioChatApi) return if (!window.tidioChatApi) return
isShow ? close() : open() isShow ? close() : open()
}
document.getElementById('chat-btn').style.display = 'block'
} else if (isChatHideShow) {
window.chatBtn = {
hide: () => window.tidioChatApi && window.tidioChatApi.hide(),
show: () => window.tidioChatApi && window.tidioChatApi.show()
}
} }
} else if (isChatHideShow) { })
window.chatBtn = {
hide: () => window.tidioChatApi && window.tidioChatApi.hide(),
show: () => window.tidioChatApi && window.tidioChatApi.show()
}
}
})() })()

View File

@@ -1,23 +0,0 @@
script.
(() => {
const panguFn = () => {
if (typeof pangu === 'object') pangu.autoSpacingPage()
else {
btf.getScript('!{url_for(theme.asset.pangu)}')
.then(() => {
pangu.autoSpacingPage()
})
}
}
const panguInit = () => {
if (!{theme.pangu.field === 'post'}){
GLOBAL_CONFIG_SITE.isPost && panguFn()
} else {
panguFn()
}
}
btf.addGlobalFn('pjaxComplete', panguInit, 'pangu')
document.addEventListener('DOMContentLoaded', panguInit)
})()

View File

@@ -1,6 +1,6 @@
{ {
"name": "hexo-theme-butterfly", "name": "hexo-theme-butterfly",
"version": "5.2.2", "version": "5.3.0-b1",
"description": "A Simple and Card UI Design theme for Hexo", "description": "A Simple and Card UI Design theme for Hexo",
"main": "package.json", "main": "package.json",
"scripts": { "scripts": {

View File

@@ -152,10 +152,6 @@ pace_js:
other_name: pace other_name: pace
file: pace.min.js file: pace.min.js
version: 1.2.4 version: 1.2.4
pangu:
name: pangu
file: dist/browser/pangu.min.js
version: 4.0.7
pjax: pjax:
name: pjax name: pjax
file: pjax.min.js file: pjax.min.js

View File

@@ -545,10 +545,6 @@ hexo.extend.filter.register('before_generate', () => {
bg_dark: '#1f1f1f' bg_dark: '#1f1f1f'
}, },
instantpage: false, instantpage: false,
pangu: {
enable: false,
field: 'site'
},
lazyload: { lazyload: {
enable: false, enable: false,
field: 'site', field: 'site',