为文档添加 AI 搜索与聊天

This commit is contained in:
Super Manito
2025-05-18 10:57:10 +08:00
parent 14a716cd7e
commit 2efff3dcc8
12 changed files with 434 additions and 61 deletions

View File

@@ -0,0 +1,30 @@
function loadOramaWebComponent() {
const searchBox = document.querySelector('orama-search-box')
if (searchBox) {
Object.assign(searchBox, getOramaSearchBoxConfig())
}
// define global function
window.openOramaSearch = function (event) {
const element = document.querySelector('orama-search-box')
if (element) {
element.open = true
localizationOramaSearchBox(element)
}
return false
}
// localization chat box component
if (searchBox) {
const openObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'open' && searchBox.hasAttribute('open')) {
localizationOramaSearchBox(searchBox)
}
})
})
openObserver.observe(searchBox, { attributes: true })
if (searchBox.hasAttribute('open')) {
localizationOramaSearchBox(searchBox)
}
}
}