mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:10:53 +08:00
✨ 添加第三方chat服務 crisp
This commit is contained in:
@@ -11,8 +11,6 @@ script.
|
||||
if (d.head) d.head.appendChild(s);
|
||||
})(document, window, 'Chatra');
|
||||
|
||||
|
||||
|
||||
if (!{theme.chat_btn}) {
|
||||
var chatBtnFn = () => {
|
||||
var chatBtn = document.getElementById("chat_btn")
|
||||
|
||||
36
layout/includes/chat/crisp.pug
Normal file
36
layout/includes/chat/crisp.pug
Normal file
@@ -0,0 +1,36 @@
|
||||
script.
|
||||
window.$crisp = [];
|
||||
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])
|
||||
|
||||
if (!{theme.chat_btn}) {
|
||||
$crisp.push(["do", "chat:hide"])
|
||||
$crisp.push(["on", "chat:closed", function() {
|
||||
$crisp.push(["do", "chat:hide"])
|
||||
}])
|
||||
var chatBtnFn = () => {
|
||||
var chatBtn = document.getElementById("chat_btn")
|
||||
chatBtn.addEventListener("click", function(){
|
||||
$crisp.push(["do", "chat:show"])
|
||||
$crisp.push(["do", "chat:open"])
|
||||
|
||||
});
|
||||
}
|
||||
chatBtnFn()
|
||||
} else {
|
||||
if (!{theme.chat_hide_show}) {
|
||||
function chatBtnHide () {
|
||||
$crisp.push(["do", "chat:hide"])
|
||||
}
|
||||
function chatBtnShow () {
|
||||
$crisp.push(["do", "chat:show"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,29 @@
|
||||
if theme.chat_btn
|
||||
script.
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
room: '#{theme.gitter.room}',
|
||||
activationElement: '#chat_btn'
|
||||
disableDefaultChat: true,
|
||||
};
|
||||
|
||||
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
|
||||
document.addEventListener('gitter-sidecar-ready', (e) => {
|
||||
const GitterChat = e.detail.Chat
|
||||
let chat
|
||||
|
||||
function initGitter () {
|
||||
chat = new GitterChat({
|
||||
room: '#{theme.gitter.room}',
|
||||
activationElement: '#chat_btn'
|
||||
});
|
||||
}
|
||||
|
||||
initGitter()
|
||||
|
||||
if (!{theme.pjax}) {
|
||||
document.addEventListener('pjax:complete', () => {
|
||||
chat.destroy()
|
||||
initGitter()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
else
|
||||
script.
|
||||
((window.gitter = {}).chat = {}).options = {
|
||||
@@ -22,4 +39,5 @@ else
|
||||
document.getElementsByClassName('gitter-open-chat-button')[0].style.display= 'block'
|
||||
}
|
||||
}
|
||||
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
|
||||
|
||||
script(src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer)
|
||||
|
||||
@@ -5,4 +5,6 @@ else if theme.tidio && theme.tidio.enable
|
||||
else if theme.daovoice && theme.daovoice.enable
|
||||
include ./daovoice.pug
|
||||
else if theme.gitter && theme.gitter.enable
|
||||
include ./gitter.pug
|
||||
include ./gitter.pug
|
||||
else if theme.crisp && theme.crisp.enable
|
||||
include ./crisp.pug
|
||||
Reference in New Issue
Block a user