MediaWiki:Gadget-FullwidthSearchFix.js:修订间差异
外观
删除的内容 添加的内容
精简繁体检测:只保留 indexOf('hant'),去掉 tw/hk/mo 补丁 |
无编辑摘要 |
||
| 第27行: | 第27行: | ||
//! src/FullwidthSearchFix/modules/redirect.ts |
//! src/FullwidthSearchFix/modules/redirect.ts |
||
var import_ext_gadget2 = require("ext.gadget.Util"); |
var import_ext_gadget2 = require("ext.gadget.Util"); |
||
//! src/FullwidthSearchFix/modules/i18n.ts |
//! src/FullwidthSearchFix/modules/i18n.ts |
||
var import_ext_gadget = require("ext.gadget.i18n"); |
|||
var getI18nMessages = () => { |
var getI18nMessages = () => { |
||
// 检测用户语言,选择简体或繁体中文 |
|||
var userLang = mw.config.get('wgUserLanguage') || 'zh-hans'; |
|||
var isTraditional = userLang.indexOf('hant') !== -1; |
|||
return { |
return { |
||
"Redirecting to": |
"Redirecting to": (0, import_ext_gadget.localize)({ |
||
en: "Redirecting to $1", |
|||
ja: "「$1」にリダイレクト中", |
|||
: "正在重定向至 |
"zh-hans": "正在重定向至“$1”", |
||
"zh-hant": "正在重新導向至“$1”" |
|||
}) |
|||
}; |
}; |
||
}; |
}; |
||
| 第65行: | 第65行: | ||
return; |
return; |
||
} |
} |
||
const colonIndex = URL_SEARCH.indexOf(" |
const colonIndex = URL_SEARCH.indexOf(":"); |
||
if (colonIndex === -1) { |
if (colonIndex === -1) { |
||
return; |
return; |
||
2026年6月14日 (日) 13:03的最新版本
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
*
* @base {@link https://zh.wikipedia.org/wiki/MediaWiki:Gadget-fullwidth-search-fix.js}
* @source {@link https://git.qiuwen.net.cn/InterfaceAdmin/QiuwenGadgets/src/branch/master/src/FullwidthSearchFix}
* @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/FullwidthSearchFix/FullwidthSearchFix.js
//! src/FullwidthSearchFix/modules/redirect.ts
var import_ext_gadget2 = require("ext.gadget.Util");
//! src/FullwidthSearchFix/modules/i18n.ts
var import_ext_gadget = require("ext.gadget.i18n");
var getI18nMessages = () => {
return {
"Redirecting to": (0, import_ext_gadget.localize)({
en: "Redirecting to $1",
ja: "「$1」にリダイレクト中",
"zh-hans": "正在重定向至“$1”",
"zh-hant": "正在重新導向至“$1”"
})
};
};
var i18nMessages = getI18nMessages();
var getMessage = (key) => {
return i18nMessages[key] || key;
};
//! src/FullwidthSearchFix/modules/redirect.ts
var import_ext_gadget3 = require("ext.gadget.Toastify");
var redirect = (nameSpace, pageName) => {
(0, import_ext_gadget3.toastify)({
text: getMessage("Redirecting to").replace("$1", "".concat(nameSpace, ":").concat(pageName)),
duration: -1
}, "info");
const {
wgScript
} = mw.config.get();
const href = new import_ext_gadget2.MwUri(wgScript, location.origin).extend({
search: "".concat(nameSpace, ":").concat(pageName)
}).toString();
location.href = href;
};
//! src/FullwidthSearchFix/FullwidthSearchFix.ts
(function fullwidthSearchFix() {
const URL_FULLTEXT = mw.util.getParamValue("fulltext");
const URL_SEARCH = mw.util.getParamValue("search");
if (URL_FULLTEXT || !URL_SEARCH) {
return;
}
const colonIndex = URL_SEARCH.indexOf(":");
if (colonIndex === -1) {
return;
}
const nameSpace = URL_SEARCH.slice(0, Math.max(0, colonIndex));
const {
wgNamespaceIds
} = mw.config.get();
if (!wgNamespaceIds[nameSpace.toLowerCase()]) {
return;
}
const pageName = URL_SEARCH.slice(Math.max(0, colonIndex + 1));
redirect(nameSpace, pageName);
})();
})();
/* </nowiki> */