首页
随机
登录
设置
关于中医百科
免责声明
中医百科
搜索
查看“︁MediaWiki:Gadget-HideLongSummaries.js”︁的源代码
←
MediaWiki:Gadget-HideLongSummaries.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/** * SPDX-License-Identifier: CC-BY-SA-4.0 * _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}' * * @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/HideLongSummaries} * @license CC-BY-SA-4.0 {@link https://www.qiuwenbaike.cn/wiki/H:CC-BY-SA-4.0} */ /** * +------------------------------------------------------------+ * | === 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/HideLongSummaries/HideLongSummaries.js //! src/HideLongSummaries/options.json function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var n = 0, F = function() { }; return { s: F, n: function() { return n >= r.length ? { done: true } : { done: false, value: r[n++] }; }, e: function(r2) { throw r2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function() { t = t.call(r); }, n: function() { var r2 = t.next(); return a = r2.done, r2; }, e: function(r2) { u = true, o = r2; }, f: function() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var maxLength = 256; //! src/HideLongSummaries/modules/constant.ts var CLASS_NAME = "gadget-hide_long_summaries"; var CLASS_NAME_LONG = "".concat(CLASS_NAME, "--long"); var CLASS_NAME_SHORT = "".concat(CLASS_NAME, "--short"); var CLASS_NAME_SWITCH = "".concat(CLASS_NAME, "-switch"); //! src/HideLongSummaries/HideLongSummaries.ts var import_ext_gadget2 = require("ext.gadget.Util"); //! src/HideLongSummaries/modules/i18n.ts var import_ext_gadget = require("ext.gadget.i18n"); var getI18nMessages = () => { return { Collapse: (0, import_ext_gadget.localize)({ en: "collapse", ja: "折り畳み", "zh-hans": "折叠", "zh-hant": "折疊" }), Expand: (0, import_ext_gadget.localize)({ en: "expand", ja: "展開", "zh-hans": "展开", "zh-hant": "展開" }) }; }; var i18nMessages = getI18nMessages(); var getMessage = (key) => { return i18nMessages[key] || key; }; //! src/HideLongSummaries/HideLongSummaries.ts void (0, import_ext_gadget2.getBody)().then(function hideLongSummaries($body) { const $switches = []; var _iterator = _createForOfIteratorHelper($body.find(".comment")), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done; ) { const element = _step.value; if (!element.textContent || element.textContent.length <= maxLength || !element.parentElement) { continue; } $(element).addClass(CLASS_NAME_LONG).hide(); $switches[$switches.length] = $("<a>").addClass(CLASS_NAME_SWITCH).text("[".concat(getMessage("Expand"), "]")).insertAfter(element); $("<span>").addClass("comment comment--without-parentheses ".concat(CLASS_NAME_SHORT)).text("".concat(element.textContent.slice(0, Math.max(0, maxLength + 1)), "...").concat(element.textContent.slice(-1))).insertAfter(element); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } for (var _i = 0, _$switches = $switches; _i < _$switches.length; _i++) { const $switch = _$switches[_i]; $switch.on("click", (event) => { const parentElement = event.currentTarget.parentElement; const $parentElement = $(parentElement); const $long = $parentElement.find(".".concat(CLASS_NAME_LONG)); const $short = $parentElement.find(".".concat(CLASS_NAME_SHORT)); $switch.text($long.is(":visible") ? "[".concat(getMessage("Expand"), "]") : "[".concat(getMessage("Collapse"), "]")); $long.toggle(); $short.toggle(); }); } }); })(); /* </nowiki> */
该页面使用的模板:
Template:Gadget Header
(
查看源代码
)
返回
MediaWiki:Gadget-HideLongSummaries.js
。