Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7890046
favicon_service.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
favicon_service.js
View Options
const
createFaviconService
=
()
=>
{
const
favicons
=
[]
const
faviconWidth
=
128
const
faviconHeight
=
128
const
badgeRadius
=
32
const
initFaviconService
=
()
=>
{
const
nodes
=
document
.
querySelectorAll
(
'link[rel="icon"]'
)
nodes
.
forEach
(
favicon
=>
{
if
(
favicon
)
{
const
favcanvas
=
document
.
createElement
(
'canvas'
)
favcanvas
.
width
=
faviconWidth
favcanvas
.
height
=
faviconHeight
const
favimg
=
new
Image
()
favimg
.
crossOrigin
=
'anonymous'
favimg
.
src
=
favicon
.
href
const
favcontext
=
favcanvas
.
getContext
(
'2d'
)
favicons
.
push
({
favcanvas
,
favimg
,
favcontext
,
favicon
})
}
})
}
const
isImageLoaded
=
(
img
)
=>
img
.
complete
&&
img
.
naturalHeight
!==
0
const
clearFaviconBadge
=
()
=>
{
if
(
favicons
.
length
===
0
)
return
favicons
.
forEach
(({
favimg
,
favcanvas
,
favcontext
,
favicon
})
=>
{
if
(
!
favimg
||
!
favcontext
||
!
favicon
)
return
favcontext
.
clearRect
(
0
,
0
,
faviconWidth
,
faviconHeight
)
if
(
isImageLoaded
(
favimg
))
{
favcontext
.
drawImage
(
favimg
,
0
,
0
,
favimg
.
width
,
favimg
.
height
,
0
,
0
,
faviconWidth
,
faviconHeight
)
}
favicon
.
href
=
favcanvas
.
toDataURL
(
'image/png'
)
})
}
const
drawFaviconBadge
=
()
=>
{
if
(
favicons
.
length
===
0
)
return
clearFaviconBadge
()
favicons
.
forEach
(({
favimg
,
favcanvas
,
favcontext
,
favicon
})
=>
{
if
(
!
favimg
||
!
favcontext
||
!
favcontext
)
return
const
style
=
getComputedStyle
(
document
.
body
)
const
badgeColor
=
`
${
style
.
getPropertyValue
(
'--badgeNotification'
)
||
'rgb(240, 100, 100)'
}
`
if
(
isImageLoaded
(
favimg
))
{
favcontext
.
drawImage
(
favimg
,
0
,
0
,
favimg
.
width
,
favimg
.
height
,
0
,
0
,
faviconWidth
,
faviconHeight
)
}
favcontext
.
fillStyle
=
badgeColor
favcontext
.
beginPath
()
favcontext
.
arc
(
faviconWidth
-
badgeRadius
,
badgeRadius
,
badgeRadius
,
0
,
2
*
Math
.
PI
,
false
)
favcontext
.
fill
()
favicon
.
href
=
favcanvas
.
toDataURL
(
'image/png'
)
})
}
return
{
initFaviconService
,
clearFaviconBadge
,
drawFaviconBadge
}
}
const
FaviconService
=
createFaviconService
()
export
default
FaviconService
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 2, 2:55 AM (21 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
487021
Default Alt Text
favicon_service.js (2 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline
Log In to Comment