mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: safe search results
This commit is contained in:
parent
ca32ac0368
commit
6b3fa3fbb3
1 changed files with 48 additions and 16 deletions
|
|
@ -5,26 +5,58 @@ const defaultFavicon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCA
|
||||||
|
|
||||||
const tabView = (result) => {
|
const tabView = (result) => {
|
||||||
const tab = result.obj
|
const tab = result.obj
|
||||||
const [label, title, url] =
|
const [label, title, url] = result.map((field) =>
|
||||||
result.map((field) => fuzzysort.highlight(field))
|
fuzzysort.highlight(field))
|
||||||
|
|
||||||
const tooltip = (tab.discarded ? `[discarded] ` : '')
|
/* Parts */
|
||||||
+ `${tab.title}\n${tab.url}`
|
|
||||||
|
|
||||||
return `
|
const labelSpan = document.createElement('span')
|
||||||
<button class='tab' data-id='${tab.id}' title='${tooltip}'>
|
labelSpan.classList.add('label')
|
||||||
<span class='label'>${label ?? tab.label}</span>
|
labelSpan.textContent = label ?? tab.label
|
||||||
<img class='favicon' src='${tab.favIconUrl ?? defaultFavicon}'/>
|
|
||||||
<div class='indicator ${tab.discarded ? 'discarded' : 'active'}'></div>
|
const faviconImg = document.createElement('img')
|
||||||
<span class='title'>${title ?? tab.title}</span>
|
faviconImg.classList.add('favicon')
|
||||||
<span class='url'>${url ?? tab.url}</span>
|
faviconImg.src = tab.favIconUrl ?? defaultFavicon
|
||||||
</button>
|
|
||||||
`
|
const indicatorDiv = document.createElement('div')
|
||||||
|
indicatorDiv.classList.add('indicator',
|
||||||
|
tab.discarded ? 'discarded' : 'active')
|
||||||
|
|
||||||
|
const titleSpan = document.createElement('span')
|
||||||
|
titleSpan.classList.add('title')
|
||||||
|
titleSpan.textContent = title ?? tab.title
|
||||||
|
|
||||||
|
const urlSpan = document.createElement('span')
|
||||||
|
urlSpan.classList.add('url')
|
||||||
|
urlSpan.textContent = url ?? tab.url
|
||||||
|
|
||||||
|
const parts = [
|
||||||
|
labelSpan,
|
||||||
|
faviconImg,
|
||||||
|
indicatorDiv,
|
||||||
|
titleSpan,
|
||||||
|
urlSpan,
|
||||||
|
]
|
||||||
|
|
||||||
|
/* Button */
|
||||||
|
|
||||||
|
const tabButton = document.createElement('button')
|
||||||
|
tabButton.classList.add('tab')
|
||||||
|
tabButton.dataset.id = tab.id
|
||||||
|
tabButton.title =
|
||||||
|
(tab.discarded ? '[discarded] ' : '') + `${tab.title}\n${tab.url}`
|
||||||
|
|
||||||
|
parts.forEach((part) => tabButton.appendChild(part))
|
||||||
|
|
||||||
|
return tabButton
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateSearchResults = (state) => {
|
export const updateSearchResults = (state) => {
|
||||||
const container = document.getElementById('searchResults')
|
const container = document.getElementById('searchResults')
|
||||||
container.innerHTML = state.results.map(tabView).join('')
|
container.innerHTML = ''
|
||||||
|
|
||||||
|
state.results.forEach((result) =>
|
||||||
|
container.appendChild(tabView(result)))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enableFaviconFallback = () => {
|
export const enableFaviconFallback = () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue