From a113b133fc8583f5c1db17010a70e9b191c9080d Mon Sep 17 00:00:00 2001 From: Coki <92775570+HashCookie@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:29:56 +0800 Subject: [PATCH] feat: update casibase widget import code (#261) --- docusaurus.config.js | 4 ---- static/js/casibase.js | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 0c3e419..6406547 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -283,10 +283,6 @@ var _hmt = _hmt || []; src: "/js/clarity.js", async: true, }, - { - src: "https://tcdn.casibase.org/casibase.js", - async: true, - }, { src: "/js/casibase.js", async: true, diff --git a/static/js/casibase.js b/static/js/casibase.js index e0de4ae..bd55edd 100644 --- a/static/js/casibase.js +++ b/static/js/casibase.js @@ -1,5 +1,16 @@ -/* eslint-disable no-undef */ -initCasibaseChat({ - endpoint: "https://ai.casbin.com", - themeColor: "rgb(64,59,121)", -}); +(function(w, d, s, c, i) { + const j = d.createElement(s); + j.async = false; + j.src = "https://tcdn.casibase.org/casibase.js"; + j.onload = function() { + w[c]("init", { + endpoint: "https://ai.casbin.com", + themeColor: "rgb(64,59,121)", + }); + }; + const f = d.getElementsByTagName(s)[0]; + f.parentNode.insertBefore(j, f); + w[c] = w[c] || function() { + (w[c].q = w[c].q || []).push(arguments); + }; +})(window, document, "script", "casibaseChat");