Add meta helper

This commit is contained in:
Talia 2022-06-13 15:43:07 +02:00
parent cf565c3eaf
commit 9d579b1dd3
1 changed files with 17 additions and 0 deletions

17
meta.js Normal file
View File

@ -0,0 +1,17 @@
export default new Proxy(document.head, {
get: (head, prop) => head.querySelector(`[name="${prop}"]`)?.content,
set: (head, prop, value) => {
let meta = head.querySelector(`[name="${prop}"]`)
if (!meta) {
meta = document.createElement("meta")
meta.name = prop
head.append(meta)
}
meta.content = value
return true
},
deleteProperty: (head, prop) => {
head.querySelector(`[name=${prop}]`)?.remove()
return true
},
})