跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
中医百科
搜索
搜索
登录
个人工具
登录
深色模式
查看“MediaWiki:Gadget-ConfirmLogout.js”的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
清除缓存
常规
链入页面
相关更改
特殊页面
页面信息
页面值
←
MediaWiki:Gadget-ConfirmLogout.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
/** * SPDX-License-Identifier: GPL-3.0-or-later * _addText: '{{Gadget Header|license=GPL-3.0-or-later}}' * * @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/ConfirmLogout} * @author 安忆 <i@anyi.in> * @license GPL-3.0-or-later {@link https://www.qiuwenbaike.cn/wiki/H:GPL-3.0} */ /** * Copyright (C) 安忆 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ /** * +------------------------------------------------------------+ * | === WARNING: GLOBAL GADGET FILE === | * +------------------------------------------------------------+ * | All changes should be made in the repository, | * | otherwise they will be lost. | * +------------------------------------------------------------+ * | Changes to this page may affect many users. | * | Please discuss changes by opening an issue before editing. | * +------------------------------------------------------------+ */ /* <nowiki> */ (() => { "use strict"; // dist/ConfirmLogout/ConfirmLogout.js function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n2) { return void e(n2); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function() { var t = this, e = arguments; return new Promise(function(r, o) { var a = n.apply(t, e); function _next(n2) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n2); } function _throw(n2) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n2); } _next(void 0); }); }; } //! src/ConfirmLogout/options.json var logoutElementSelector = '#ca-cb-logout>a,#topbar>a[href*="UserLogout"],#pt-logout>a'; var logoutElementSelectorOfVector2022StickyHeader = "#pt-logout-sticky-header>a"; var version = "3.0"; //! src/ConfirmLogout/modules/i18n.ts var import_ext_gadget = require("ext.gadget.i18n"); var getI18nMessages = () => { return { "Network error": (0, import_ext_gadget.localize)({ en: "Network error", ja: "ネットワークエラー", "zh-hans": "网络异常", "zh-hant": "網路異常" }), Confirm: (0, import_ext_gadget.localize)({ en: "Confirm logout?", ja: "ログアウトしますか?", "zh-hans": "您确定要退出吗?", "zh-hant": "您確定要登出嗎?" }), Succeed: (0, import_ext_gadget.localize)({ en: "Logout succeed. Refreshing...", ja: "ログアウトに成功しました。再読み込みします...", "zh-hans": "退出成功,即将刷新页面……", "zh-hant": "登出成功,即將重新載入……" }) }; }; var i18nMessages = getI18nMessages(); var getMessage = (key) => { return i18nMessages[key] || key; }; //! src/ConfirmLogout/modules/addListener.ts var import_ext_gadget6 = require("ext.gadget.Util"); //! src/ConfirmLogout/modules/util/refreshEventListener.ts var import_ext_gadget2 = require("ext.gadget.FilterAlteredClicks"); var refreshEventListener = ($element, clickListener2) => { const hoverListener = () => { $element.off("click"); $element.on("click", (0, import_ext_gadget2.filterAlteredClicks)(clickListener2)); }; const hoverListenerWithDebounce = mw.util.debounce(hoverListener, 200, true); $element.on("mouseover touchstart", hoverListenerWithDebounce); }; //! src/ConfirmLogout/modules/addListener.ts var import_ext_gadget7 = require("ext.gadget.Toastify"); //! src/ConfirmLogout/modules/api.ts var import_ext_gadget3 = require("ext.gadget.Util"); var api = (0, import_ext_gadget3.initMwApi)("ConfirmLogout/".concat(version)); //! src/ConfirmLogout/modules/util/logout.ts var import_ext_gadget4 = require("ext.gadget.Toastify"); var logout = /* @__PURE__ */ function() { var _ref = _asyncToGenerator(function* (toastifyInstance) { yield api.postWithEditToken({ action: "logout" }); toastifyInstance.hideToast(); (0, import_ext_gadget4.toastify)({ text: getMessage("Succeed") }, "success"); location.reload(); }); return function logout2(_x) { return _ref.apply(this, arguments); }; }(); //! src/ConfirmLogout/modules/util/showError.ts var import_ext_gadget5 = require("ext.gadget.Toastify"); var showError = (error, toastifyInstance) => { console.error("[ConfirmLogout] Ajax error:", error); toastifyInstance.hideToast(); (0, import_ext_gadget5.toastify)({ text: getMessage("Network error") }, "error"); }; //! src/ConfirmLogout/modules/tryLogout.ts var tryLogout = /* @__PURE__ */ function() { var _ref2 = _asyncToGenerator(function* (toastifyInstance) { try { yield logout(toastifyInstance); } catch (error) { showError(error, toastifyInstance); } }); return function tryLogout2(_x2) { return _ref2.apply(this, arguments); }; }(); //! src/ConfirmLogout/modules/addListener.ts var { skin } = mw.config.get(); var clickListener = /* @__PURE__ */ function() { var _ref3 = _asyncToGenerator(function* (event) { event.preventDefault(); const isConfirm = yield (0, import_ext_gadget6.oouiConfirmWithStyle)(getMessage("Confirm")); if (!isConfirm) { return; } const toastifyInstance = (0, import_ext_gadget7.toastify)({ text: mw.msg("logging-out-notify"), duration: -1 }, "info"); void tryLogout(toastifyInstance); }); return function clickListener2(_x3) { return _ref3.apply(this, arguments); }; }(); var addListener = ($element) => { var _$body$get; refreshEventListener($element, (event) => { void clickListener(event); }); if (skin !== "vector-2022") { return; } const $body = $element.parents("body"); const observerCallback = (_mutations, observer) => { if (!$body.hasClass("vector-sticky-header-visible")) { return; } const SELECTOR = logoutElementSelectorOfVector2022StickyHeader; const element = document.querySelector(SELECTOR); if (!element) { return; } const elementClone = element.cloneNode(true); element.replaceWith(elementClone); refreshEventListener($body.find(SELECTOR), (event) => { void clickListener(event); }); observer.disconnect(); }; const mutationObserver = new MutationObserver(observerCallback); mutationObserver.observe((_$body$get = $body.get(0)) !== null && _$body$get !== void 0 ? _$body$get : document.documentElement, { attributes: true, attributeFilter: ["class"] }); }; //! src/ConfirmLogout/ConfirmLogout.ts var import_ext_gadget8 = require("ext.gadget.Util"); var { wgUserName } = mw.config.get(); void (0, import_ext_gadget8.getBody)().then(function confirmLogout($body) { if (!wgUserName) { return; } const $element = $body.find(logoutElementSelector); if (!$element.length) { return; } addListener($element); }); })();
该页面使用的模板:
Template:Gadget Header
(
查看源代码
)
返回
MediaWiki:Gadget-ConfirmLogout.js
。
开关有限宽度模式