MediaWiki:Gadget-confirm-logout.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
* Copyright (c) 2020-present, 安忆.
*
* @author 安忆 [[zh:U:安忆]]
* @file ConfirmLogout.js
* @license GPL v3
*/
$(function confirmLogout() {
var $body = $(document).find('body');
var $element = $().add($body.find('#ca-cb-logout>a,#topbar>a[href*="UserLogout"],#pt-logout>a')).add($body.find('.minerva-icon--logOut').parent('.minerva-user-menu,.toggle-list-item__anchor').not('[target]'));
if (!$element.length || !mw.config.get('wgUserName')) {
return;
}
var clickListener = function clickListener(event) {
event.preventDefault();
OO.ui.confirm($('<div>').addClass('oo-ui-window-foot').css({
border: '.1rem solid #0645ad',
display: 'flex',
'justify-content': 'space-evenly'
}).append($('<span>').css({
'font-size': '1.2rem',
'font-weight': '500',
'line-height': '1.8',
padding: '.4em 0'
}).text('您' + wgULS('确', '確') + '定要' + wgULS('退', '登') + '出' + wgULS('吗', '嗎') + '?'))).then(function (isConfirm) {
if (!isConfirm) {
return;
}
window.bldkDingExposedInterface(mw.message('logging-out-notify'), 'default', 'long');
new mw.Api().postWithEditToken({
action: 'logout'
}).then(function () {
location.reload();
});
});
};
var refreshEventListener = function refreshEventListener(_$element) {
var hoverListener = function hoverListener() {
_$element.off('click');
_$element.on('click', clickListener);
};
var hoverListenerWithDebounce = mw.util.debounce(hoverListener, 200, true);
_$element.on('mouseover touchstart', hoverListenerWithDebounce);
};
refreshEventListener($element);
if (mw.config.get('skin') !== 'vector-2022') {
return;
}
var observerCallback = function observerCallback(_mutations, observer) {
if (!$body.hasClass('vector-sticky-header-visible')) {
return;
}
var SELECTOR = '#pt-logout-sticky-header>a';
var element = document.querySelector(SELECTOR);
if (!element) {
return;
}
var elementClone = element.cloneNode(true);
element.replaceWith(elementClone);
refreshEventListener($(SELECTOR));
observer.disconnect();
};
var mutationObserver = new MutationObserver(observerCallback);
mutationObserver.observe(document.body, {
attributes: true,
attributeFilter: ['class']
});
});