MediaWiki:Gadget-confirm-logout.js

勤求古训,博采众方

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/*!
 * @author 安忆 [[zh:User:AnYiLin]]
 * @file ConfirmLogout.js
 *
 * Copyright (c) 2021-present, 安忆.
 *
 * This source code is licensed under the GPL v3 license.
 */
(function($, mw) {
	var confirmLogout = function() {
		var dom = document.querySelector('#ca-cb-logout>a') || document.querySelector('.menu__item--logout') || document.querySelector('#pt-logout>a');
		if (dom && RLCONF.wgUserName) {
			var newDom = document.createElement('a');
			dom.className && (newDom.className = dom.className);
			newDom.href = dom.href;
			newDom.innerHTML = dom.innerHTML;
			dom.parentNode.appendChild(newDom);
			dom.parentNode.removeChild(dom); //ES6: dom.remove()
			newDom.addEventListener('click', function(e) {
				e.preventDefault();
				e.stopPropagation();
				OO.ui.confirm($('<div class="oo-ui-window-foot" style="border:.1rem solid #0645ad;display:flex;justify-content:space-evenly"><span style="font-size:1.2rem;font-weight:500;line-height:1.8;padding:.4em 0">您' + wgUVS('确', '確') + '定要' + wgUVS('退', '登') + '出' + wgUVS('吗', '嗎') +'?</span></div>')).then(function(confirmed) {
					if (confirmed) {
						window.bldkDingExposedInterface(mw.message('logging-out-notify'), 'default', 'long');
						new mw.Api().postWithEditToken({
							action: 'logout'
						}).then(function() {
							window.location.reload()
						})
					}
				})
			})
		}
	};
	$(confirmLogout)
})(jQuery, mw);