36 lines
1 KiB
JavaScript
36 lines
1 KiB
JavaScript
#include html.js
|
|
|
|
const $meta = (() => {
|
|
return {
|
|
get(name, prefixed=true) {
|
|
if(!name) return;
|
|
if(prefixed) name = `msz-${name}`;
|
|
|
|
const elem = $query(`meta[name="${name}"]`);
|
|
if(elem instanceof HTMLMetaElement && typeof elem.content === 'string')
|
|
return elem.content;
|
|
|
|
return null;
|
|
},
|
|
set(name, value, prefixed=true) {
|
|
if(!name) return;
|
|
if(prefixed) name = `msz-${name}`;
|
|
|
|
let elem = $query(`meta[name="${name}"]`);
|
|
if(elem instanceof HTMLMetaElement) {
|
|
if(typeof value === 'string')
|
|
elem.content = value;
|
|
else
|
|
elem.remove();
|
|
} else {
|
|
if(typeof value !== 'string')
|
|
return;
|
|
|
|
elem = document.createElement('meta');
|
|
elem.name = name;
|
|
elem.content = value;
|
|
document.head.appendChild(elem);
|
|
}
|
|
},
|
|
};
|
|
})();
|