var vap_tags=document.getElementById("vap_tags");
var roles=document.getElementById("roles");
var rolues_value=document.getElementById("roles_value");
if(roles){
roles.addEventListener("click", function(){
rolues_value.disabled = !roles.checked;
genValues();
});
}
if(rolues_value){
rolues_value.addEventListener("change", genValues);
rolues_value.addEventListener("keydown", genValues);
rolues_value.addEventListener("cut", genValues);
rolues_value.addEventListener("paste", genValues);
}
var authors=document.getElementById("authors");
var authors_value=document.getElementById("authors_value");
if(authors){
authors.addEventListener("click", function(){
authors_value.disabled = !authors.checked;
genValues();
});
}
if(authors_value){
authors_value.addEventListener("change", genValues);
authors_value.addEventListener("keydown", genValues);
authors_value.addEventListener("cut", genValues);
authors_value.addEventListener("paste", genValues);
}
var counter=document.getElementById("counter");
var counter_value=document.getElementById("counter_value");
if(counter){
counter.addEventListener("click", function(){
counter_value.disabled = !counter.checked;
genValues();
});
}
if(counter_value){
counter_value.addEventListener("change", genValues);
counter_value.addEventListener("keydown", genValues);
counter_value.addEventListener("cut", genValues);
counter_value.addEventListener("paste", genValues);
}
var bio=document.getElementById("bio");
if(bio){
bio.addEventListener("click", function(){
genValues();
});
}
var avatar=document.getElementById("avatar");
if(avatar){
avatar.addEventListener("click", function(){
genValues();
});
}
var border=document.getElementById("border");
if(border){
border.addEventListener("click", function(){
genValues();
});
}
function attachValue(tagBox, key, el){
tagBox.value=tagBox.value.slice(0, tagBox.value.length-1)+' ' + key;
if(el!==null){
tagBox.value +='="'+el.value+'"';
}
tagBox.value +=']';
}
function genValues(){
vap_tags.value="[vauthors_page]";
if(roles.checked){
attachValue(vap_tags, 'roles', rolues_value);
}
if(authors.checked){
attachValue(vap_tags, 'authors', authors_value);
}
if(counter.checked){
attachValue(vap_tags, 'counter', counter_value);
}
if(bio.checked){
attachValue(vap_tags, "bio", null);
}
if(avatar.checked){
attachValue(vap_tags, "avatar", null);
}
if(border.checked){
attachValue(vap_tags, "border", null);
}};
class authorshipByline{constructor(t,i){this.type=i,this.byline=t,this.valid=!0,this.names=[],this.links=[],this.href=this.byline.getAttribute("href"),this.url=new URL(decodeURIComponent(this.href)),this.params=new URLSearchParams(this.url.search),this.origin=this.url.origin,this.path=this.url.pathname,this.postId=0,this.params.has("mab_v3")&&(this.postId=this.params.get("mab_v3")),this.lang="",this.params.has("lang")&&(this.lang="?lang="+this.params.get("lang")),this.check()?this.parseData():this.valid=!1}check(){let t=!0;return""===(this.byline.textContent||"").trim()&&(this.params.has("m_main_disabled")?this.byline.removeAttribute("href"):this.byline.setAttribute("href",this.origin+this.path+this.lang),t=!1),t}parseData(){switch(this.type){case"v1":case"v2":var t=[molongui_authorship_byline_params.byline_separator,molongui_authorship_byline_params.byline_last_separator];this.names=this.byline.innerText.split(new RegExp(t.join("|"),"gi")),this.params.has("m_main_disabled")?(this.links=this.params.getAll("mca"),this.links.unshift("molongui-disabled-link")):(t=this.path.replace(/^\/|\/$/g,"").split("/").pop(),this.path.replace(/\/$/g,"").replace(t,""),this.links=this.params.getAll("mca"),this.links.unshift(this.origin+this.path+this.lang));break;case"v3":var t=window["molongui_authorship_byline_data_"+this.postId];Object.values(t).forEach(function(t){this.names.push(t.name),this.links.push(t.url)},this),this.names.length!==this.links.length&&(t="Byline for post #"+this.postId+" is probably wrong, names count doesn't match links count.",console.log("%c MOLONGUI AUTHORSHIP %c\n"+t+"\n"+this.byline,"background: #fdfdc6; font-weight: bold; color: #555",""))}}replace(){let e=[molongui_authorship_byline_params.byline_separator,molongui_authorship_byline_params.byline_last_separator],s="",n=this.names.length,t=this.byline.getAttribute("class"),i=this.byline.getAttribute("target"),a=this.byline.getAttribute("rel"),l=this.byline.getAttribute("itemprop");var r='class="'+(t?t+" ":"")+molongui_authorship_byline_params.byline_link_class+'"',o=i?'target="'+i+'"':"",h=a?'rel="'+a+'"':"",u=l?'itemprop="'+l+'"':"";s=molongui_authorship_byline_params.byline_dom_prepend;for(let i=0;i<n;i++){var m=this.names[i].trim();let t="";t=""!==molongui_authorship_byline_params.byline_dom_tree?molongui_authorship_byline_params.byline_dom_tree.replace("{%ma_authorName}",m):m,!this.links[i]||0===this.links[i].length||"molongui-disabled-link"===this.links[i]||i>=this.links.length?s+=t:s+='<a href="'+this.links[i]+'" '+r+" "+h+" "+u+" "+o+' title="'+molongui_authorship_byline_params.byline_link_title+" "+m+'">'+t+"</a>",i<n-1-1?s+=e[0]:i<n-1&&(s+=e[1])}s+=molongui_authorship_byline_params.byline_dom_append,this.byline.insertAdjacentHTML("afterend",s),this.byline.parentNode.removeChild(this.byline)}isValid(){return this.valid}getNames(){return this.names}getLinks(){return this.links}}let getBylines=function(t){let i;return i="v3"===t?document.querySelectorAll('a[href*="mab_v3="]'):document.querySelectorAll('a[href*="molongui_byline=old"]')};const __molonguiProcessedBylines=new WeakSet;let addBylineCoauthors=function(){let s=molongui_authorship_byline_params.byline_decoder;var t=getBylines(s);Array.prototype.forEach.call(t,function(t,i){var e;__molonguiProcessedBylines.has(t)||(e=new authorshipByline(t,s)).isValid()&&(e.replace(),__molonguiProcessedBylines.add(t))})},addBylineModifiers=function(){const e="?m_bm=true";var t=document.querySelectorAll('a[href$="'+e+'"]');Array.prototype.forEach.call(t,function(t,i){t.setAttribute("href",decodeURIComponent(t.getAttribute("href")).replace(e,"")),t.insertAdjacentHTML("beforebegin",molongui_authorship_byline_params.byline_prefix+" "),t.insertAdjacentHTML("afterend"," "+molongui_authorship_byline_params.byline_suffix)})},removeEmptyLinks=function(){var t=document.querySelectorAll('a[href="#molongui-disabled-link"]');Array.prototype.forEach.call(t,function(t,i){t.classList.add("molongui-disabled-link"),t.removeAttribute("href")})},initBylines=function(){addBylineModifiers(),addBylineCoauthors(),removeEmptyLinks()};document.addEventListener("DOMContentLoaded",function(){initBylines();var t=document.body;new MutationObserver(function(t){Array.prototype.forEach.call(t,function(t,i){void 0!==t.target.classList&&"m-a-box-container"===t.target.classList.value||initBylines()})}).observe(t,{attributes:!0,childList:!0,subtree:!0,characterData:!0})});