为文档添加 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,47 @@
function loadOramaWebComponent() {
const searchBox = document.querySelector('orama-search-box')
if (searchBox) {
Object.assign(searchBox, getOramaSearchBoxConfig())
}
// custom button style and localization
const searchButton = document.querySelector('orama-search-button')
if (searchButton) {
searchButton.textContent = '搜索'
const observer = new MutationObserver((mutations, obs) => {
if (searchButton.shadowRoot) {
const button = searchButton.shadowRoot.querySelector('button')
if (button) {
button.style = 'border-radius: 8px !important;'
button.querySelector('.button__label').style = 'height: 22px; padding: 2px 8px; font-size: 0.75rem;'
button.querySelector('span[slot="adorment-end"], .kyb-shortcut').style = 'display: none;'
// search icon style
const magnifyingGlassShadowRoot = button.querySelector('ph-magnifying-glass').shadowRoot
const styleElement = document.createElement('style')
styleElement.textContent = `
svg {
font-size: 24px;
}`
if (!magnifyingGlassShadowRoot.querySelector('style[data-custom="icon-style"]')) {
styleElement.setAttribute('data-custom', 'icon-style')
magnifyingGlassShadowRoot.appendChild(styleElement)
}
obs.disconnect()
}
}
})
observer.observe(searchButton, {
childList: true,
subtree: true,
attributes: true,
characterData: true,
})
setTimeout(() => observer.disconnect(), 2000)
}
searchButton.addEventListener('click', function () {
const searchBox = document.querySelector('orama-search-box')
// localization chat box component
localizationOramaSearchBox(searchBox)
})
}