js/meta.js

18 lines
443 B
JavaScript
Raw Normal View History

2022-06-13 13:43:07 +00:00
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
},
})