User:魔琴/gadgets/legacy-2022/lang-list.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
mw.loader.using( ['mediawiki.util', 'ext.gadget.site-lib'/* ,'ext.gadget.HanAssist'*/ ], function () {
function han(s, t) {
return wgULS(s, t);
//return HanAssist.localize( { hans: s, hant: t } );
}
if (mw.config.get('skin') !== 'vector-2022')
return;
mw.loader.load('/w/index.php?title=User:魔琴/gadgets/legacy-2022/lang-list.css&action=raw&ctype=text/css', 'text/css');
var j = {};
var s = "";
var q = true;
var ac = 0;
const regions = ['WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA', 'all']
var show = han('展开','展開')
var hide = han('折叠','摺叠')
$('#p-lang-btn-sticky-header').click();
const iid = setInterval(checkloaded, 20);
function checkloaded() {
for (i = 0; i < regions.length; i++) {
ac = ac + $('.uls-language-list .uls-lcd-region-section[data-region=' + regions[i] + '] a').length
}
$('#p-lang-btn-sticky-header').click();
if ($('.uls-language-list .uls-empty-state').length !== 0 || ac !== 0) {
clearInterval(iid);
$('.uls-menu').css('display','none');
$("#p-lang-btn-sticky-header").removeClass("selector-open")
main();
}
}
function main() {
if ($('.uls-lcd-quicklist').length === 0) {
q = false
}
$('.uls-language-list .interlanguage-link a').each(function () {
s = $(this).attr('lang');
d = $(this).parent().attr('class').replace(/^.*interwiki-(.*?) .*$/, '$1')
j[s] = {}
j[s]['dblang'] = d
j[s]['href'] = $(this).attr('href');
j[s]['title'] = $(this).attr('title');
j[s]['name'] = $(this).html();
if ($(this).parent().hasClass('badge-featuredlist') || $(this).parent().hasClass('badge-featuredarticle')) {
j[s]['status'] = 'F'
} else if ($(this).parent().hasClass('badge-goodarticle')) {
j[s]['status'] = 'G'
} else {
j[s]['status'] = 'unknown'
}
if (q) {
if ($('.interwiki-' + d).closest('.uls-lcd-quicklist').length !== 0) {
j[s]['show'] = 'quick'
} else {
j[s]['show'] = 'slow'
}
} else {
j[s]['show'] = 'plain'
}
s = ""
d = ""
});
const r = Object.keys(j).sort().reduce(
(obj, key) => {
obj[key] = j[key];
return obj;
},
{}
);
$('#vector-main-menu').append($('<div>').addClass('vector-menu-content legacy-lang-div').attr('id', 'legacy-lang-menu-container'))
$('#legacy-lang-menu-container').append($('<div>').addClass('vector-menu-heading').html(han('语言','語言')).attr('id', 'legacy-lang-menu-header'))
$('#legacy-lang-menu-container').append($('<div>').addClass('vector-menu-content').attr('id', 'legacy-lang-div'))
$('#legacy-lang-div').append($('<ul>').addClass('vector-menu-content-list legacy-lang-li').attr('id', 'legacy-lang-ul'))
if(q){
var showBtn = $('<button>').addClass('vector-pinnable-header-toggle-button legacy-lang-show-btn legacy-lang-show-btn-show').html(show).css('display','inline-block')
$('#legacy-lang-menu-header').append(showBtn)
$('#legacy-lang-ul').addClass('legacy-lang-ul-show')
$('.legacy-lang-show-btn').click(function (e) {
e.preventDefault();
if ($(this).hasClass('legacy-lang-show-btn-show')) {
$('#legacy-lang-ul').removeClass('legacy-lang-ul-show').addClass('legacy-lang-ul-hide')
$(this).removeClass('legacy-lang-show-btn-show').addClass('legacy-lang-show-btn-hide').html(hide)
} else {
$('#legacy-lang-ul').removeClass('legacy-lang-ul-hide').addClass('legacy-lang-ul-show')
$(this).removeClass('legacy-lang-show-btn-hide').addClass('legacy-lang-show-btn-show').html(show)
}
})
}
for (const key in r) {
if (r.hasOwnProperty(key)) {
li = $('<li>').addClass('interlanguage-link').addClass('interwiki-' + r[key]['dblang']).addClass('mw-list-item legacy-lang-li legacy-lang-status-' + r[key]['status']).addClass('legacy-lang-show-' + r[key]['show'])
a = $('<a>').addClass('interlanguage-link-target').attr('href', r[key]['href']).attr('title', r[key]['title']).attr('lang', key).attr('hreflang', key)
span = $('<span>').html(r[key]['name'])
$(a).append(span);
$(li).append(a);
$('#legacy-lang-ul').append(li);
}
}
$('.vector-language-sidebar-alert').closest('div').css('display', 'none')
}
});