-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (31 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const original = document.querySelector('[name="description"]').content
/**
* Dinamically manipulates the description metatag dinamically.
* @param {string} text - The new content to insert in meta tag.
* @return The new content of description meta tag.
*/
function set (text) {
let metatag = document.querySelector('[name="description"]')
let metaItemProp = document.querySelector('[itemprop="description"]')
if (metatag) {
metatag.content = text
} else {
let metaDescription = document.createElement('meta')
metaDescription.setAttribute('name', 'description')
metaDescription.setAttribute('content', text)
document.head.appendChild(metaDescription)
}
if (metaItemProp) {
metaItemProp.content = text
} else {
let metaItemProp = document.createElement('meta')
metaItemProp.setAttribute('itemprop', 'description')
metaItemProp.setAttribute('content', text)
document.head.appendChild(metaItemProp)
}
}
exports = module.exports = set
exports.reset = function () {
set(original)
}