MediaWiki:Common.js
Chú ý: Sau khi lưu trang, có thể bạn sẽ phải xóa bộ nhớ đệm của trình duyệt để xem các thay đổi.
- Firefox / Safari: Nhấn giữ phím Shift trong khi nhấn Tải lại (Reload), hoặc nhấn tổ hợp Ctrl-F5 hay Ctrl-R (⌘R trên Mac)
- Google Chrome: Nhấn tổ hợp Ctrl-Shift-R (⇧⌘R trên Mac)
- Internet Explorer / Edge: Nhấn giữ phím Ctrl trong khi nhấn Làm tươi (Refresh), hoặc nhấn tổ hợp Ctrl-F5
- Opera: Nhấn tổ hợp Ctrl-F5.
// Example columns var dl = document.getElementsByTagName('dl'); 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++) { 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) {dd[j].style.setProperty('min-width','100%'); dd[j].style.setProperty('column-span','all')} } if (cnt >= 6) { dl[i].style.columns = 2 } } // 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 * 3 + 10 && cognates[c].querySelectorAll('li').length > 7) { cognates[c].style.columnCount = 3; } else if (document.querySelector('.cognates .reference-text').clientWidth > widestwidth * 2 + 10 && cognates[c].querySelectorAll('li').length > 4) { cognates[c].style.columnCount = 2; } else { cognates[c].style.columnCount = 1; } } } cogcol(); window.addEventListener('resize', cogcol) 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('[title="Edit this page [alt-shift-e]"]').click(); }; if (e.key === 'r' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { e.preventDefault(); document.querySelector('[title="Remove invalid links [alt-shift-r]"]').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) { 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(' ')) + ' ' + 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(' ')) + ' ' + 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(' > ','<con> > </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++) { console.log(i); textimg[i].querySelector('img').src = 'https://www.tunguyentiengviet.com/images/4/47/Placeholder.png'; i++; } }