Bước tới nội dung

Khác biệt giữa bản sửa đổi của “MediaWiki:Common.js”

Từ Từ nguyên Tiếng Việt
Không có tóm lược sửa đổi
Thẻ: Sửa đổi di động Sửa đổi từ trang di động Sửa đổi di động nâng cao
Không có tóm lược sửa đổi
Thẻ: Lùi lại thủ công
 
(không hiển thị 74 phiên bản ở giữa của cùng người dùng)
Dòng 1: Dòng 1:
window.isMobile = /iphone|ipod|ipad|android|blackberry|opera mini|opera mobi|skyfire|maemo|windows phone|palm|iemobile|symbian|symbianos|fennec/i.test(navigator.userAgent.toLowerCase());
if (!window.isMobile) {
// Display zoomed text
var ht = document.getElementsByClassName('Hani');
if (ht.length > 0) {
    for (var i = 0; i < ht.length; i++) {
        ht[i].innerHTML = '<div class="tttext">' + ht[i].innerHTML + '<span class="ttzoom"> ' + ht[i].innerHTML + '</span></div>';
    }
}
var hc = document.getElementsByClassName('notHani');
if (hc.length > 0) {
    for (var i = 0; i < hc.length; i++) {
        hc[i].innerHTML = '<div class="tttext">' + hc[i].innerHTML + '<span class="ttzoom"> ' + hc[i].innerHTML + '</span></div>';
    }
}
// Zoomed text to left if overflow
var ttzoom = document.querySelectorAll('.ttzoom')
for (tt = 0; tt < ttzoom.length; tt++) {
    if (ttzoom[tt].getBoundingClientRect().right > window.innerWidth) {
        ttzoom[tt].style.left = '-800%'
    }
// Hide empty ruby text
var rt = document.getElementsByTagName('rt');
if (rt.length > 0) {
    for (var i = 0; i < rt.length; i++) {
        if (rt[i].innerText == '') { rt[i].style.display = 'none' };
    }
}
// Example columns
// Example columns
var dl = document.getElementsByTagName('dl');
function excol() {
var cnt = 0;
    var dl = document.getElementsByTagName('dl');
for (var i = 0; i < dl.length; i++) {
    var maxwidth = 0;
    cnt = 0;
    var cnt = 0;
    var dd = dl[i].getElementsByTagName('dd');
    for (var i = 0; i < dl.length; i++) {
    for (j = 0; j < dd.length; j++) {
        cnt = 0;
        if (dd[j].innerText != '\n') { cnt++; } else { cnt = 0; dd[j].style.columnSpan = 'all'; dd[j-1].style.columnSpan = 'all'; };
        var dd = dl[i].getElementsByTagName('dd');
        if (dd[j].clientWidth > dl[i].clientWidth) {dd[j].style.setProperty('min-width','100%'); dd[j].style.setProperty('column-span','all')}
        for (j = 0; j < dd.length; j++) {
            dd[j].style.setProperty('min-width', 'max-content');
            dd[j].style.setProperty('column-span', 'unset');
            if (dd[j].clientWidth + parseFloat(window.getComputedStyle(dd[j]).marginLeft) > dl[i].clientWidth / 2) {
                dd[j].style.setProperty('min-width', 'calc(100% - 1.6em)');
                dd[j].style.setProperty('column-span', 'all');
            }
            if (maxwidth < dd[j].clientWidth && dd[j].style.minWidth != 'calc(100% - 1.6em)') {
                maxwidth = dd[j].clientWidth + parseFloat(window.getComputedStyle(dd[j]).marginLeft) + 5;
            }
        console.log(maxwidth);
        cnt++;
        }
        if (cnt >= 6 && maxwidth * 3 < dl[i].clientWidth) {
            dl[i].style.columns = 3
        } else if (cnt >= 6 && maxwidth * 2 < dl[i].clientWidth && maxwidth * 3 > dl[i].clientWidth) {
            dl[i].style.columns = 2
        } else {
            dl[i].style.columns = 1
        }  
     }
     }
    if (cnt >= 6) { dl[i].style.columns = 2 }
}
}


Dòng 53: Dòng 38:
         var coglis = cognates[c].querySelectorAll('li');
         var coglis = cognates[c].querySelectorAll('li');
         for (var l = 0; l < coglis.length; l++) {
         for (var l = 0; l < coglis.length; l++) {
             if (widest == null) {  
             if (widest == null) {
                 widestwidth = coglis[l].clientWidth;
                 widestwidth = coglis[l].clientWidth;
                 widest = l;
                 widest = l;
             } else if (widestwidth < coglis[l].clientWidth) {
             } else if (widestwidth < coglis[l].clientWidth) {
                 widestwidth = coglis[l].clientWidth
                 widestwidth = coglis[l].clientWidth;
                 widest = l;
                 widest = l;
             }
             }
         }
         }


         if (document.querySelector('.cognates .reference-text').clientWidth > widestwidth * 3 + 10 && cognates[c].querySelectorAll('li').length > 7) {
         if (document.querySelector('.cognates .reference-text').clientWidth > (widestwidth + parseFloat(window.getComputedStyle(document.querySelector('.reference-text ol'))['marginLeft'])) * 3 + 10 && cognates[c].querySelectorAll('li').length > 7) {
             cognates[c].style.columnCount = 3;
             cognates[c].style.columnCount = 3;
         } else if (document.querySelector('.cognates .reference-text').clientWidth > widestwidth * 2 + 10 && cognates[c].querySelectorAll('li').length > 4) {
         } else if (document.querySelector('.cognates .reference-text').clientWidth > (widestwidth + parseFloat(window.getComputedStyle(document.querySelector('.reference-text ol'))['marginLeft'])) * 2 + 10 && cognates[c].querySelectorAll('li').length > 4) {
             cognates[c].style.columnCount = 2;
             cognates[c].style.columnCount = 2;
         } else {
         } else {
Dòng 71: Dòng 56:
     }
     }
}
}
excol();
cogcol();
cogcol();
window.addEventListener('resize', cogcol)
window.addEventListener('resize', () => {
 
     cogcol();
// TEST
     excol();
for (i = 0; i < ht.length; i++) {
})
     if (ht[i].innerText == '\uFFFD') {
        ht[i].innerText = 'Missing font!';
    }
}
for (i = 0; i < hc.length; i++) {
     if (hc[i].innerText == '\uFFFD') {
        hc[i].innerText = 'Missing font!';
    }
}


if (document.querySelector('.notelistalpha') != null && document.querySelector('.notelistalpha').childElementCount < 2) { document.querySelector('.notelistalpha').style.visibility = 'hidden' };
if (document.querySelector('.notelistalpha') != null && document.querySelector('.notelistalpha').childElementCount < 2) { document.querySelector('.notelistalpha').style.visibility = 'hidden' };
Dòng 106: Dòng 83:
     if (e.key === 'e' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
     if (e.key === 'e' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
         e.preventDefault();
         e.preventDefault();
         document.querySelector('[title="Edit this page [alt-shift-e]"]').click();
         document.querySelector('a[accesskey="e"]').click();
    };
    if (e.key === 'r' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('input[accesskey="r"]').click();
    };
    if (e.key === 'g' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('input[accesskey="g"]').click();
     };
     };
}, false);
}, false);
Dòng 123: Dòng 108:
// Line-break arrows
// Line-break arrows
var entries = '';
var entries = '';
if (window.location.href.search('index.php') < 0) {
if (window.location.href.search('index.php') < 0 && window.location.href.lastIndexOf(':') == 5) {
entries = document.querySelector('ol').querySelectorAll('li');
    entries = document.querySelector('ol').querySelectorAll('li');
for (i = 0; i < entries.length; i++) {
    for (i = 0; i < entries.length; i++) {
    if (entries[i].innerHTML.match(/> →/g) != null) {
        if (entries[i].innerHTML.match(/> →/g) != null) {
        var entry = entries[i].innerHTML.split('> →');
            var entry = entries[i].innerHTML.split('> →');
        entries[i].innerHTML = '';
            entries[i].innerHTML = '';
        entries[i].innerHTML += entry[0] + 'b>';
            entries[i].innerHTML += entry[0] + 'b>';
        for (j = 1; j < entry.length - 1; j++) {
            for (j = 1; j < entry.length - 1; j++) {
            entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + (j + 1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '' + entry[j] + '></span>';
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + (j + 1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[j] + '></span>';
        }
            }
        if (entry[entry.length - 1].search('dl') > -1 && entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).slice(entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).length - 2) != '<a') {
            if (entry[entry.length - 1].search('dl') > -1 && entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).slice(entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).length - 2) != '<a') {
            entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '' + entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].split('<dl')[0].slice(entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ') + 1) + '</span><dl' + entry[entry.length - 1].split('<dl')[1];
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].split('<dl')[0].slice(entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ') + 1) + '</span><dl' + entry[entry.length - 1].split('<dl')[1];
        } else if (entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') - 2, entry[entry.length - 1].lastIndexOf(' ')) != '<a') {
            } else if (entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') - 2, entry[entry.length - 1].lastIndexOf(' ')) != '<a') {
            entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '' + entry[entry.length - 1].slice(0, entry[entry.length - 1].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') + 1) + '</span>';
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1].slice(0, entry[entry.length - 1].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') + 1) + '</span>';
        } else {
            } else {
            entries[0].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '' + entry[entry.length - 1]
                entries[0].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1]
            }
         }
         }
     }
     }
}
}
}
// Remove double spaces & replace Word Connectors * replace → arrow
// Remove double spaces
if (window.location.href.indexOf('MediaWiki') == -1) {
if (window.location.href.indexOf('MediaWiki') == -1) {
     document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll('  ', ' ');
     document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll('  ', ' ');
}
if (window.location.href.indexOf('index') == -1) {
    document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll(' &gt; ', '<con> &gt; </con>').replaceAll(' ~ ', '<con> ~ </con>');
}
}


Dòng 184: Dòng 172:
     zoombtn[vid].setAttribute("onclick", "enlarge(" + vid + ")");
     zoombtn[vid].setAttribute("onclick", "enlarge(" + vid + ")");
     zoombtn[vid].setAttribute("title", "Thu nhỏ");
     zoombtn[vid].setAttribute("title", "Thu nhỏ");
}
}
}


if (window.isMobile) {
// Display zoomed text
/* Tất cả mã JavaScript đặt ở đây sẽ được tải cho người sử dụng trang di động */
var ht = document.getElementsByClassName('Hani');
var ht = document.getElementsByClassName('Hani');
var hc = document.getElementsByClassName('notHani');
if (ht.length > 0) {
var mf = document.getElementsByClassName('missing message note');
    for (var i = 0; i < ht.length; i++) {
var mb = document.getElementsByClassName('maybe');
        ht[i].innerHTML = '<div class="tttext">' + ht[i].innerHTML + '<span class="ttzoom"> ' + ht[i].innerHTML + '</span></div>';
 
function missingfont() {
    event.stopPropagation();
    if ( document.querySelector('.missing.message.popup') != null ) {
        document.querySelector('.missing.message.popup').remove();
     }
     }
    if ( document.querySelector('.maybe.message.popup') != null ) {
        document.querySelector('.maybe.message.popup').remove();
    }
    const mfpopup = document. createElement('span');
    mfpopup.innerHTML = '<span class="drawer drawer-container__drawer position-fixed text references-drawer visible">Đây là ký tự Hán cổ hoặc Nôm, không được hỗ trợ trên đa số các dòng điện thoại. Bạn cần chuyển sang sử dụng máy tính và tải thêm font Hán Nôm để hiển thị.</span>';
    mfpopup.setAttribute('class','missing message popup');
    document.body.appendChild(mfpopup);
}
}
for (i = 0; i < mf.length; i++) {
var hc = document.getElementsByClassName('notHani');
  mf[i].setAttribute('onclick','missingfont()');
if (hc.length > 0) {
}
    for (var i = 0; i < hc.length; i++) {
function maybe() {
        hc[i].innerHTML = '<div class="tttext">' + hc[i].innerHTML + '<span class="ttzoom"> ' + hc[i].innerHTML + '</span></div>';
    event.stopPropagation();
    if ( document.querySelector('.missing.message.popup') != null ) {
        document.querySelector('.missing.message.popup').remove();
     }
     }
    if ( document.querySelector('.maybe.message.popup') != null ) {
        document.querySelector('.maybe.message.popup').remove();
    }
    const mbpopup = document. createElement('span');
    mbpopup.innerHTML = '<span class="drawer drawer-container__drawer position-fixed text references-drawer visible">Có thể. Không có dẫn chứng chắc chắn.</span>';
    mbpopup.setAttribute('class','maybe message popup');
    document.body.appendChild(mbpopup);
}
for (i = 0; i < mb.length; i++) {
  mb[i].setAttribute('onclick','maybe()');
}
}


function popup(a) {
// Zoomed text to left if overflow
    event.stopPropagation();
var ttzoom = document.querySelectorAll('.ttzoom')
    if (a.getElementsByClassName('ttzoom')[0].style.visibility == 'hidden') {
for (tt = 0; tt < ttzoom.length; tt++) {
        for ( var i = 0; i < ht.length; i++ ) {
    if (ttzoom[tt].getBoundingClientRect().right + 20 > window.innerWidth) {
          ht[i].getElementsByClassName('ttzoom')[0].style.visibility = 'hidden';
         ttzoom[tt].style.left = '-800%'
          ht[i].getElementsByClassName('ttzoom')[0].style.opacity = '0';
        }
        a.getElementsByClassName('ttzoom')[0].style.visibility = 'visible';
        a.getElementsByClassName('ttzoom')[0].style.opacity = '1';
    } else {
         a.getElementsByClassName('ttzoom')[0].style.visibility = 'hidden';
        a.getElementsByClassName('ttzoom')[0].style.opacity = '0';
     }
     }
}
}
function popdown() {
// Hide empty ruby text
    for ( var i = 0; i < ht.length; i++ ) {
        ht[i].getElementsByClassName('ttzoom')[0].style.visibility = 'hidden';
        ht[i].getElementsByClassName('ttzoom')[0].style.opacity = '0';
    }
    for ( var i = 0; i < hc.length; i++ ) {
        hc[i].getElementsByClassName('ttzoom')[0].style.visibility = 'hidden';
        hc[i].getElementsByClassName('ttzoom')[0].style.opacity = '0';
    }
    if ( document.querySelector('.missing.message.popup') != null ) {
        document.querySelector('.missing.message.popup').remove();
    }
    if ( document.querySelector('.maybe.message.popup') != null ) {
        document.querySelector('.maybe.message.popup').remove();
    }
}
if ( ht.length > 0 ) {
    for ( var i = 0; i < ht.length; i++ ) {
        ht[ i ].innerHTML = '<div class="tttext" onclick="popup(ht['+i+'])">' + ht[ i ].innerHTML + '<span class="ttzoom" style="visibility:hidden"> ' + ht[ i ].innerHTML + '</span></div>';
    }
}
if ( hc.length > 0 ) {
    for ( var i = 0; i < hc.length; i++ ) {
        hc[ i ].innerHTML = '<div class="tttext" onclick="popup(hc['+i+'])">' + hc[ i ].innerHTML + '<span class="ttzoom" style="visibility:hidden"> ' + hc[ i ].innerHTML + '</span></div>';
    }
}
 
document.addEventListener('click', popdown, false);
 
var rt = document.getElementsByTagName('rt');
var rt = document.getElementsByTagName('rt');
if ( rt.length > 0 ) {
if (rt.length > 0) {
     for ( var i = 0; i < rt.length; i++ ) {
     for (var i = 0; i < rt.length; i++) {
        if ( rt[i].innerText == '' ) { rt[i].style.display = 'none' };
        if (rt[i].innerText == '') { rt[i].style.display = 'none' };
    }
}
 
var zoom = document.getElementsByClassName('ttzoom');
for ( var i = 0; i < zoom.length; i++ ) {
    if ( zoom[i].getBoundingClientRect().right > document.documentElement.clientWidth ) {
        zoom[i].style.left = 'unset';
        zoom[i].style.right = '100%';
    }
}
 
/* Remove space before citation */
var citerefs = document.querySelectorAll('[id^="cite_ref-"]');
if (citerefs.length > 0) {
  for (var i = 0; i < citerefs.length; i++) {
    if (citerefs[i].childNodes[0].textContent == ' ') {
      citerefs[i].childNodes[0].textContent = '';
     }
     }
  }
  citerefs[0].parentElement.innerHTML = citerefs[0].parentElement.innerHTML.replaceAll(' <sup id="cite_ref-','<sup id="cite_ref-');
};
/* Set citation title */
options = {childList: true}, observer = new MutationObserver(onChanged);
function onChanged(mutations) {
//  for (var mutation of mutations) {
if (mutations[0].type === 'childList') {
setTimeout(function() {
if (document.querySelector('.drawer').querySelector('sup').innerText == '[a]') {
document.querySelector('.references-drawer__title').innerText = 'Ghi chú';
}
if (document.querySelector('.drawer').querySelector('sup').innerText == '[cg1]') {
document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc';
}
}, 500);
}
//  }
}
}


observer.observe(document.body, options);


//Line-break arrows
// Replace textimg
var entries = document.querySelector('ol').querySelectorAll('li');
var textimg = document.querySelectorAll('[class*="textimg"]');
for (i = 0; i < entries.length; i++) {
if (textimg.length > 0) {
  if (entries[i].innerHTML.match(/> →/g) != null) {
     for (var i = 0; i < textimg.length; i++) {
     var entry = entries[i].innerHTML.split('> →');
        textimg[i].querySelector('img').src = 'https://www.tunguyentiengviet.com/images/4/47/Placeholder.png';
    entries[i].innerHTML = '';
        i++;
    entries[i].innerHTML += entry[0] + 'b>';
    for (j = 1; j < entry.length - 1; j++) {
      entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + (j+1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '→' + entry[j] + '></span>';
    }
    if (entry[entry.length-1].search('dl') > -1 && entry[entry.length-1].split('<dl')[0].slice(0,entry[entry.length-1].split('<dl')[0].lastIndexOf(' ')).slice(entry[entry.length-1].split('<dl')[0].slice(0,entry[entry.length-1].split('<dl')[0].lastIndexOf(' ')).length-2) != '<a') {
      entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '→' + entry[entry.length-1].split('<dl')[0].slice(0,entry[entry.length-1].split('<dl')[0].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length-1].split('<dl')[0].slice(entry[entry.length-1].split('<dl')[0].lastIndexOf(' ')+1) + '</span><dl' + entry[entry.length-1].split('<dl')[1];
    } else {
      entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '→' + entry[entry.length-1].slice(0,entry[entry.length-1].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length-1].slice(entry[entry.length-1].lastIndexOf(' ') + 1) + '</span>';
     }
     }
  }
}
}


// Example columns
// Highlight entry
var dl = document.getElementsByTagName('dl');
if (window.location.href.includes('#entry')) {
var cnt = 0;
     document.getElementById(window.location.href.substring(window.location.href.indexOf('#')+1,window.location.href.length)).parentElement.style.background = "rgba(255,222,100,0.4)"
for (var i = 0; i < dl.length; i++) {
     cnt = 0;
    var dd = dl[i].getElementsByTagName('dd');
    for (j = 0; j < dd.length; j++) {
        if (dd[j].innerText != '\n') { cnt++; } else { cnt = 0; dd[j].style.columnSpan = 'all'; dd[j-1].style.columnSpan = 'all'; };
        if (dd[j].clientWidth > dl[i].clientWidth/2) {dd[j].style.setProperty('min-width','100%'); dd[j].style.setProperty('column-span','all')}
    }
    if (cnt >= 6) { dl[i].style.columns = 2 }
}
}
}

Bản mới nhất lúc 10:38, ngày 30 tháng 4 năm 2026

// Example columns
function excol() {
    var dl = document.getElementsByTagName('dl');
    var maxwidth = 0;
    var cnt = 0;
    for (var i = 0; i < dl.length; i++) {
        cnt = 0;
        var dd = dl[i].getElementsByTagName('dd');
        for (j = 0; j < dd.length; j++) {
            dd[j].style.setProperty('min-width', 'max-content');
            dd[j].style.setProperty('column-span', 'unset');
            if (dd[j].clientWidth + parseFloat(window.getComputedStyle(dd[j]).marginLeft) > dl[i].clientWidth / 2) {
                dd[j].style.setProperty('min-width', 'calc(100% - 1.6em)');
                dd[j].style.setProperty('column-span', 'all');
            }
            if (maxwidth < dd[j].clientWidth && dd[j].style.minWidth != 'calc(100% - 1.6em)') {
                maxwidth = dd[j].clientWidth + parseFloat(window.getComputedStyle(dd[j]).marginLeft) + 5;
            }
        console.log(maxwidth);
        cnt++;
        }
        if (cnt >= 6 && maxwidth * 3 < dl[i].clientWidth) {
            dl[i].style.columns = 3
        } else if (cnt >= 6 && maxwidth * 2 < dl[i].clientWidth && maxwidth * 3 > dl[i].clientWidth) {
            dl[i].style.columns = 2
        } else {
            dl[i].style.columns = 1
        } 
    }
}

// Cognates columns
function cogcol() {
    var cognates = document.querySelectorAll('.cognates ul');
    for (var c = 0; c < cognates.length; c++) {
        var widest = null;
        var widestwidth = 0;
        var coglis = cognates[c].querySelectorAll('li');
        for (var l = 0; l < coglis.length; l++) {
            if (widest == null) {
                widestwidth = coglis[l].clientWidth;
                widest = l;
            } else if (widestwidth < coglis[l].clientWidth) {
                widestwidth = coglis[l].clientWidth;
                widest = l;
            }
        }

        if (document.querySelector('.cognates .reference-text').clientWidth > (widestwidth + parseFloat(window.getComputedStyle(document.querySelector('.reference-text ol'))['marginLeft'])) * 3 + 10 && cognates[c].querySelectorAll('li').length > 7) {
            cognates[c].style.columnCount = 3;
        } else if (document.querySelector('.cognates .reference-text').clientWidth > (widestwidth + parseFloat(window.getComputedStyle(document.querySelector('.reference-text ol'))['marginLeft'])) * 2 + 10 && cognates[c].querySelectorAll('li').length > 4) {
            cognates[c].style.columnCount = 2;
        } else {
            cognates[c].style.columnCount = 1;
        }
    }
}
excol();
cogcol();
window.addEventListener('resize', () => {
    cogcol();
    excol();
})

if (document.querySelector('.notelistalpha') != null && document.querySelector('.notelistalpha').childElementCount < 2) { document.querySelector('.notelistalpha').style.visibility = 'hidden' };

// Wikipedia links
var wlinks = document.getElementsByClassName('extiw');
for (var i = 0; i < wlinks.length; i++) {
    wlinks[i].title = wlinks[i].title.replace('wikipedia:vi:', '')
}

// CTRL + shortcuts
document.addEventListener("keydown", function(e) {
    if (e.key === 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('[value="Save changes"]').click();
    };
    if (e.key === 'p' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('[value="Show preview"]').click();
    };
    if (e.key === 'e' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('a[accesskey="e"]').click();
    };
    if (e.key === 'r' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('input[accesskey="r"]').click();
    };
    if (e.key === 'g' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
        e.preventDefault();
        document.querySelector('input[accesskey="g"]').click();
    };
}, false);

// Remove space before citation
var citerefs = document.querySelectorAll('[id^="cite_ref-"]');
if (citerefs.length > 0) {
    for (var i = 0; i < citerefs.length; i++) {
        if (citerefs[i].childNodes[0].textContent == ' ') {
            citerefs[i].childNodes[0].textContent = '';
        }
    }
    citerefs[0].parentElement.innerHTML = citerefs[0].parentElement.innerHTML.replaceAll(' <sup id="cite_ref-', '<sup id="cite_ref-');
}

// Line-break arrows
var entries = '';
if (window.location.href.search('index.php') < 0 && window.location.href.lastIndexOf(':') == 5) {
    entries = document.querySelector('ol').querySelectorAll('li');
    for (i = 0; i < entries.length; i++) {
        if (entries[i].innerHTML.match(/> →/g) != null) {
            var entry = entries[i].innerHTML.split('> →');
            entries[i].innerHTML = '';
            entries[i].innerHTML += entry[0] + 'b>';
            for (j = 1; j < entry.length - 1; j++) {
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + (j + 1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[j] + '></span>';
            }
            if (entry[entry.length - 1].search('dl') > -1 && entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).slice(entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')).length - 2) != '<a') {
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1].split('<dl')[0].slice(0, entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].split('<dl')[0].slice(entry[entry.length - 1].split('<dl')[0].lastIndexOf(' ') + 1) + '</span><dl' + entry[entry.length - 1].split('<dl')[1];
            } else if (entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') - 2, entry[entry.length - 1].lastIndexOf(' ')) != '<a') {
                entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1].slice(0, entry[entry.length - 1].lastIndexOf(' ')) + '&nbsp;' + entry[entry.length - 1].slice(entry[entry.length - 1].lastIndexOf(' ') + 1) + '</span>';
            } else {
                entries[0].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + entry.length + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '<arrow>↳ </arrow>' + entry[entry.length - 1]
            }
        }
    }
}
// Remove double spaces & replace Word Connectors * replace → arrow
if (window.location.href.indexOf('MediaWiki') == -1) {
    document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll('  ', ' ');
}
if (window.location.href.indexOf('index') == -1) {
    document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll(' &gt; ', '<con> &gt; </con>').replaceAll(' ~ ', '<con> ~ </con>');
}

// Zoom Videos
var zoombtn = document.getElementsByClassName("enlarge");
for (var i = 0; i < zoombtn.length; i++) {
    zoombtn[i].setAttribute("onclick", "enlarge(" + i + ")");
    zoombtn[i].setAttribute("title", "Phóng to");
}
var video = document.querySelectorAll('[title="Play video"]');

function enlarge(vid) {
    video[vid].width *= 2;
    video[vid].height *= 2;
    video[vid].style.setProperty("height", video[vid].height + "px");
    video[vid].style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.style.setProperty("height", video[vid].height + "px");
    video[vid].parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    zoombtn[vid].setAttribute("onclick", "smaller(" + vid + ")");
    zoombtn[vid].setAttribute("title", "Thu nhỏ");
}

function smaller(vid) {
    video[vid].width /= 2;
    video[vid].height /= 2;
    video[vid].style.setProperty("height", video[vid].height + "px");
    video[vid].style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.style.setProperty("height", video[vid].height + "px");
    video[vid].parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    video[vid].parentElement.parentElement.parentElement.style.setProperty("width", video[vid].width + "px");
    zoombtn[vid].setAttribute("onclick", "enlarge(" + vid + ")");
    zoombtn[vid].setAttribute("title", "Thu nhỏ");
}

// Display zoomed text
var ht = document.getElementsByClassName('Hani');
if (ht.length > 0) {
    for (var i = 0; i < ht.length; i++) {
        ht[i].innerHTML = '<div class="tttext">' + ht[i].innerHTML + '<span class="ttzoom"> ' + ht[i].innerHTML + '</span></div>';
    }
}
var hc = document.getElementsByClassName('notHani');
if (hc.length > 0) {
    for (var i = 0; i < hc.length; i++) {
        hc[i].innerHTML = '<div class="tttext">' + hc[i].innerHTML + '<span class="ttzoom"> ' + hc[i].innerHTML + '</span></div>';
    }
}

// Zoomed text to left if overflow
var ttzoom = document.querySelectorAll('.ttzoom')
for (tt = 0; tt < ttzoom.length; tt++) {
    if (ttzoom[tt].getBoundingClientRect().right + 20 > window.innerWidth) {
        ttzoom[tt].style.left = '-800%'
    }
}
// Hide empty ruby text
var rt = document.getElementsByTagName('rt');
if (rt.length > 0) {
    for (var i = 0; i < rt.length; i++) {
        if (rt[i].innerText == '') { rt[i].style.display = 'none' };
    }
}


// Replace textimg
var textimg = document.querySelectorAll('[class*="textimg"]');
if (textimg.length > 0) {
    for (var i = 0; i < textimg.length; i++) {
        textimg[i].querySelector('img').src = 'https://www.tunguyentiengviet.com/images/4/47/Placeholder.png';
        i++;
    }
}

// Highlight entry
if (window.location.href.includes('#entry')) {
    document.getElementById(window.location.href.substring(window.location.href.indexOf('#')+1,window.location.href.length)).parentElement.style.background = "rgba(255,222,100,0.4)"
}