]*>)?([^<]*)(<\/a>)?(?:\s*<\/p>)/gis,
'$1')
.replace(
/((?:src|href)=")(?:\.\.\/)*([^"]*")/gis,
'$1' + window.location.origin + '/$2');
}
function parseMeta(html) {
let x;
var re = /]*?>([^=<]*?)\s*=\s*(.*?)<\/p>/gis;
while ((x = re.exec(html)) !== null) {
var key = x[1].toLowerCase();
var txt = x[2];
if (key == '' || txt == '') continue;
switch (key) {
case 'title':
var node = document.createElement('title');
node.innerHTML = txt;
document.head.appendChild(node);
case 'og:title':
makeMetaTagByProp('og:title', txt);
break;
case 'description':
case 'desc':
makeMetaTagByName('description', txt);
case 'og:description':
case 'og:desc':
makeMetaTagByProp('og:description', txt);
break;
case 'published':
case 'article:published_time':
makeMetaTagByProp('article:published_time', txt);
break;
case 'modified':
case 'article:modified_time':
makeMetaTagByProp('article:modified_time', txt);
break;
case 'image':
case 'og:image':
makeMetaTagByProp('og:image', new URL(txt, window.location.href));
break;
case 'site':
case 'og:site_name':
makeMetaTagByProp('og:site_name', txt);
break;
case 'type':
case 'og:type':
makeMetaTagByProp('og:type', txt);
break;
case 'url':
case 'og:url':
makeMetaTagByProp('og:url', txt);
break;
case 'twitter':
makeMetaTagByName('twitter:site', '@' + txt);
break;
case 'robots':
makeMetaTagByName('robots', txt);
break;
case 'lang':
case 'language':
var a = document.querySelector('html');
if (a != null)
a.setAttribute('lang', txt);
break;
case 'key':
case 'keywords':
makeMetaTagByName('keywords', txt);
break;
case 'author':
makeMetaTagByName('author', txt);
makeMetaTagByName('publisher', txt);
break;
}
}
}
var seoEn = false;
function isSeoEnabled() {
if (!seoEn) {
var tag = document.querySelector('seo');
seoEn |= tag != null && tag.hasAttribute('enable');
}
return seoEn;
}
function seo() {
makeLinkTag('rel', 'canonical', 'href', window.location.href);
makeMetaTagByProp('og:title', document.title);
makeMetaTagByProp('og:url', window.location.href);
makeMetaTagByProp('og:type', 'website');
makeMetaTagByName('twitter:card', 'summary');
['title', 'description', 'image', 'url'].forEach(s => {
var a = document.querySelector('meta[property="og:' + s + '"]');
makeMetaTagByName('twitter:' + s,
a ? a.getAttribute('content') : '');
});
makeHrefLang();
}
function makeTag(parent, tag, a1, a1txt, a2, a2txt, a3, a3txt) {
if (!parent || !tag) return null;
var d = document.createElement(tag);
if (a1) d.setAttribute(a1, a1txt);
if (a2) d.setAttribute(a2, a2txt);
if (a3) d.setAttribute(a3, a3txt);
parent.appendChild(d);
return d;
}
function makeLinkTag(a1, a1txt, a2, a2txt, a3, a3txt) {
makeTag(document.head, 'link', a1, a1txt, a2, a2txt, a3, a3txt);
}
function makeMetaTag(a1, a1txt, a2, a2txt, a3, a3txt) {
makeTag(document.head, 'meta', a1, a1txt, a2, a2txt, a3, a3txt);
}
function makeMetaTagByName(name, content) {
if (document.querySelector('meta[name="' + name + '"]') == null)
makeMetaTag('name', name, 'content', content);
}
function makeMetaTagByProp(prop, content) {
if (document.querySelector('meta[property="' + prop + '"]') == null)
makeMetaTag('property', prop, 'content', content);
}
function makeHrefLang() {
document.querySelectorAll('div#sec-langs ul li p a').forEach(element => {
var h = new URL(element.getAttribute('href'), window.location.href);
var l = element.getAttribute('lng').toLowerCase();
makeLinkTag('rel', 'alternate', 'href', h, 'hreflang', l);
});
}
function languageVerify() {
var arr = [];
var doc = document.querySelector('html').getAttribute('lang');
var langs = document.querySelectorAll('div#sec-langs ul li p a');
if (langs.length == 0) return;
langs.forEach((e, i) => {
var l = e.getAttribute('lng');
var re = RegExp('^/(' + l + '|' + doc + ')/', 'gi');
var p = '/' + l + window.location.pathname.replace(re, '/');
if (i == 0) p = p.replace(re, '/');
e.setAttribute('href', window.location.origin + p);
arr.push({
'l': l,
't': e.getAttribute('title'),
'h': e.getAttribute('href'),
'x': e.innerHTML
});
});
var def = arr[0].h;
makeLinkTag('rel', 'alternate', 'href', def, 'hreflang', 'x-default');
arr.sort((a, b) => { return a.l > b.l; });
langs.forEach((e, i) => {
var a = arr[i];
e.setAttribute('lng', a.l);
e.setAttribute('title', a.t);
e.setAttribute('href', a.h);
e.innerHTML = a.x;
});
var loc = navigator.language.split('-')[0];
arr.forEach(e => { if (e.l == loc) return def = e.h; });
var cur = localStorage.getItem('lang');
if (cur == null) {
localStorage.setItem('lang', loc);
document.location.href = def;
} else
if (cur != doc)
localStorage.setItem('lang', doc);
}