mirror of
https://github.com/He4eT/tabswiper.git
synced 2026-05-05 00:57:23 +00:00
popup/tabswiper: extract dom manupulations
This commit is contained in:
parent
6b7d425f1e
commit
5ac43772ab
1 changed files with 25 additions and 0 deletions
25
popup/tabswiper/modules/dom.js
Normal file
25
popup/tabswiper/modules/dom.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* https://png-pixel.com/ */
|
||||
const defaultFavicon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkqAcAAIUAgUW0RjgAAAAASUVORK5CYII='
|
||||
|
||||
export const updateInterface = (state) => {
|
||||
const tokens = [
|
||||
['favicon', 'src', state.currentTab.favIconUrl ?? defaultFavicon],
|
||||
['tabTotalNumber', 'textContent', state.tabs.length],
|
||||
['tabNumber', 'textContent', state.tabs.length - state.tabs.findIndex(({ id }) =>
|
||||
id === state.currentTab.id
|
||||
)],
|
||||
['currentTab', 'href', state.currentTab.url],
|
||||
['tabTitle', 'textContent', state.currentTab.title],
|
||||
['tabURL', 'textContent', state.currentTab.url],
|
||||
]
|
||||
|
||||
tokens.forEach(([elementId, property, value]) => {
|
||||
document.getElementById(elementId)[property] = value
|
||||
})
|
||||
}
|
||||
|
||||
export const enableFaviconFallback = () => {
|
||||
document.getElementById('favicon').addEventListener('error', (e) => {
|
||||
e.currentTarget.src = defaultFavicon
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue