Khác biệt giữa bản sửa đổi của “MediaWiki:Mobile.js”
Giao diện
Không có tóm lược sửa đổi Thẻ: Đã bị lùi lại |
Không có tóm lược sửa đổi |
||
| (không hiển thị 21 phiên bản ở giữa của cùng người dùng) | |||
| Dòng 18: | Dòng 18: | ||
document.body.appendChild(mfpopup); | document.body.appendChild(mfpopup); | ||
} | } | ||
for (i = 0; i < mf.length; i++) { | for (var i = 0; i < mf.length; i++) { | ||
mf[i].setAttribute('onclick','missingfont()'); | mf[i].setAttribute('onclick','missingfont()'); | ||
} | } | ||
| Dòng 40: | Dòng 40: | ||
mbpopup.setAttribute('class','maybe message popup'); | mbpopup.setAttribute('class','maybe message popup'); | ||
document.body.appendChild(mbpopup); | document.body.appendChild(mbpopup); | ||
} | } | ||
for (i = 0; i < mb.length; i++) { | |||
for (var i = 0; i < mb.length; i++) { | |||
console.log(i); | console.log(i); | ||
if (mb[i].title == "Do TNTV tự phục dựng.") | if (mb[i].title == "Do TNTV tự phục dựng.") | ||
{ | { | ||
mb[i | mb[i].setAttribute('onclick','maybe("x")') | ||
} | } | ||
if (mb[i].title == "Có thể. Không có dẫn chứng chắc chắn.") | if (mb[i].title == "Có thể. Không có dẫn chứng chắc chắn.") | ||
{ | { | ||
mb[i | mb[i].setAttribute('onclick','maybe()') | ||
} | } | ||
} | } | ||
| Dòng 106: | Dòng 105: | ||
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' }; | ||
} | } | ||
} | } | ||
| Dòng 134: | Dòng 125: | ||
if (mutations[0].type === 'childList') { | if (mutations[0].type === 'childList') { | ||
setTimeout(function() { | setTimeout(function() { | ||
if (document.querySelector('.drawer').querySelector('sup').innerText | if (document.querySelector('.drawer').querySelector('sup').innerText.search(/\[[a-z]\]/) == 0) { | ||
document.querySelector('.references-drawer__title').innerText = 'Ghi chú'; | document.querySelector('.references-drawer__title').innerText = 'Ghi chú'; | ||
} | } | ||
if (document.querySelector('.drawer').querySelector('sup').innerText | if (document.querySelector('.drawer').querySelector('sup').innerText.includes('[cg')) { | ||
document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc'; | document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc'; | ||
} | } | ||
if (document.querySelector('.drawer').querySelector('sup').innerText.includes('[fc')) { | |||
document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc giả'; | |||
} | |||
if (document.querySelector('.drawer').querySelector('sup').innerText.search(/\[[1-9]\]/) == 0) { | |||
document.querySelector('.references-drawer__title').innerText = 'Nguồn tham khảo'; | |||
} | |||
}, 500); | }, 500); | ||
} | } | ||
| Dòng 149: | Dòng 146: | ||
//Line-break arrows | //Line-break arrows | ||
var entries = document.querySelector('ol').querySelectorAll('li'); | var entries = document.querySelector('ol').querySelectorAll('li'); | ||
for (i = 0; i < entries.length; i++) { | for (var 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('> →'); | ||
| Dòng 155: | Dòng 152: | ||
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(' + | entries[i].innerHTML += '<br><span style="display:inline-block;margin-left:calc(' + j + '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') { | 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(' ')) + ' ' + 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-1) + '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(' ')) + ' ' + 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 { | } 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(' ')) + ' ' + 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-1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '→' + entry[entry.length-1].slice(0,entry[entry.length-1].lastIndexOf(' ')) + ' ' + entry[entry.length-1].slice(entry[entry.length-1].lastIndexOf(' ') + 1) + '</span>'; | ||
} | } | ||
} | } | ||
| Dòng 173: | Dòng 170: | ||
for (j = 0; j < dd.length; j++) { | 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].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 (dd[j].clientWidth + parseFloat(window.getComputedStyle(dd[0])['marginLeft']) > dl[i].clientWidth/2) {dd[j].style.setProperty('min-width','100%'); dd[j].style.setProperty('column-span','all')} | ||
} | } | ||
if (cnt >= | if (cnt >= 4) { dl[i].style.columns = 2 } | ||
} | |||
// Word connectors | |||
if (window.location.href.indexOf('MediaWiki') == -1) { | |||
document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll(' > ','<con> > </con>').replaceAll(' ~ ','<con> ~ </con>').replaceAll('→ ','<arrow>↳ </arrow>'); | |||
} | |||
// 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)" | |||
} | } | ||
Bản mới nhất lúc 20:20, ngày 28 tháng 6 năm 2025
/* 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 hc = document.getElementsByClassName('notHani');
var mf = document.getElementsByClassName('missing message note');
var mb = document.getElementsByClassName('maybe');
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 (var i = 0; i < mf.length; i++) {
mf[i].setAttribute('onclick','missingfont()');
}
function maybe(e) {
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');
if (e=="x")
{
mbpopup.innerHTML = '<span class="drawer drawer-container__drawer position-fixed text references-drawer visible">Do TNTV tự phục dựng.</span>';
}
else
{
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 (var i = 0; i < mb.length; i++) {
console.log(i);
if (mb[i].title == "Do TNTV tự phục dựng.")
{
mb[i].setAttribute('onclick','maybe("x")')
}
if (mb[i].title == "Có thể. Không có dẫn chứng chắc chắn.")
{
mb[i].setAttribute('onclick','maybe()')
}
}
function popup(a) {
event.stopPropagation();
if (a.getElementsByClassName('ttzoom')[0].style.visibility == 'hidden') {
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';
}
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() {
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');
if ( rt.length > 0 ) {
for ( var i = 0; i < rt.length; i++ ) {
if ( rt[i].innerText == '' ) { rt[i].style.display = 'none' };
}
}
/* 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.search(/\[[a-z]\]/) == 0) {
document.querySelector('.references-drawer__title').innerText = 'Ghi chú';
}
if (document.querySelector('.drawer').querySelector('sup').innerText.includes('[cg')) {
document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc';
}
if (document.querySelector('.drawer').querySelector('sup').innerText.includes('[fc')) {
document.querySelector('.references-drawer__title').innerText = 'Từ cùng gốc giả';
}
if (document.querySelector('.drawer').querySelector('sup').innerText.search(/\[[1-9]\]/) == 0) {
document.querySelector('.references-drawer__title').innerText = 'Nguồn tham khảo';
}
}, 500);
}
// }
}
observer.observe(document.body, options);
//Line-break arrows
var entries = document.querySelector('ol').querySelectorAll('li');
for (var 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 + '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-1) + '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(' ')) + ' ' + 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-1) + 'em + 0.5ch);text-indent: calc(-1em - 0.5ch)">' + '→' + entry[entry.length-1].slice(0,entry[entry.length-1].lastIndexOf(' ')) + ' ' + entry[entry.length-1].slice(entry[entry.length-1].lastIndexOf(' ') + 1) + '</span>';
}
}
}
// 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 + parseFloat(window.getComputedStyle(dd[0])['marginLeft']) > dl[i].clientWidth/2) {dd[j].style.setProperty('min-width','100%'); dd[j].style.setProperty('column-span','all')}
}
if (cnt >= 4) { dl[i].style.columns = 2 }
}
// Word connectors
if (window.location.href.indexOf('MediaWiki') == -1) {
document.getElementById('mw-content-text').innerHTML = document.getElementById('mw-content-text').innerHTML.replaceAll(' > ','<con> > </con>').replaceAll(' ~ ','<con> ~ </con>').replaceAll('→ ','<arrow>↳ </arrow>');
}
// 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)"
}