Add meta-tag domProxy

This commit is contained in:
Talia 2024-02-06 22:56:08 +01:00
parent 0a80d860df
commit 8876dcfa68
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

View file

@ -59,3 +59,16 @@ export const domArray = (methods, extra) => {
return new Proxy(element, traps)
}
}
export const meta = (element=document.head) => new Proxy(element, {
get: (target, name) => target.querySelector(`meta[name="${name}"]`)?.content,
set: (target, name, value) => {
let meta = target.querySelector(`meta[name="${name}"]`)
if (!meta) {
meta = document.createElement("meta")
meta.name = name
target.append(meta)
}
meta.content = value
}
})