<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://cs.zybkcn.com/w/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-HanAssist.js</id>
	<title>MediaWiki:Gadget-HanAssist.js - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://cs.zybkcn.com/w/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AGadget-HanAssist.js"/>
	<link rel="alternate" type="text/html" href="https://cs.zybkcn.com/w/index.php?title=MediaWiki:Gadget-HanAssist.js&amp;action=history"/>
	<updated>2026-12-03T18:57:55Z</updated>
	<subtitle>本wiki上该页面的修订历史</subtitle>
	<generator>MediaWiki 1.47.0</generator>
	<entry>
		<id>https://cs.zybkcn.com/w/index.php?title=MediaWiki:Gadget-HanAssist.js&amp;diff=141&amp;oldid=prev</id>
		<title>鹿野耕云：创建页面，内容为“/**!  *  _________________________________________________________________________________  * |                                                                                 |  * |                      === WARNING: GLOBAL GADGET FILE ===                        |  * |                    Changes to this page affect many users.                      |  * |  Please discuss changes on the talk page, WP:VPT or GitHub before editing.  |  * |______________________…”</title>
		<link rel="alternate" type="text/html" href="https://cs.zybkcn.com/w/index.php?title=MediaWiki:Gadget-HanAssist.js&amp;diff=141&amp;oldid=prev"/>
		<updated>2025-11-10T05:29:04Z</updated>

		<summary type="html">&lt;p&gt;创建页面，内容为“/**!  *  _________________________________________________________________________________  * |                                                                                 |  * |                      === WARNING: GLOBAL GADGET FILE ===                        |  * |                    Changes to this page affect many users.                      |  * |  Please discuss changes on the talk page, &lt;a href=&quot;/w/index.php?title=WP:VPT&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:VPT（页面不存在）&quot;&gt;WP:VPT&lt;/a&gt; or GitHub before editing.  |  * |______________________…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**!&lt;br /&gt;
 *  _________________________________________________________________________________&lt;br /&gt;
 * |                                                                                 |&lt;br /&gt;
 * |                      === WARNING: GLOBAL GADGET FILE ===                        |&lt;br /&gt;
 * |                    Changes to this page affect many users.                      |&lt;br /&gt;
 * |  Please discuss changes on the talk page, [[WP:VPT]] or GitHub before editing.  |&lt;br /&gt;
 * |_________________________________________________________________________________|&lt;br /&gt;
 *&lt;br /&gt;
 * Built from source code at HanAssist GitHub repository https://github.com/wikimedia-gadgets/HanAssist.&lt;br /&gt;
 * All changes should be made in the repository, otherwise they will be lost.&lt;br /&gt;
 *&lt;br /&gt;
 * To update this script from GitHub, you must have a local repository set up. Then&lt;br /&gt;
 * follow the instructions at https://github.com/wikimedia-gadgets/HanAssist/blob/main/README.MD#%E6%9E%84%E5%BB%BA%E6%96%B9%E6%B3%95.&lt;br /&gt;
 *&lt;br /&gt;
 * For license information, see https://github.com/wikimedia-gadgets/HanAssist/blob/main/LICENSE.&lt;br /&gt;
 */&lt;br /&gt;
// &amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(function (global, factory) {&lt;br /&gt;
    typeof exports === &amp;#039;object&amp;#039; &amp;amp;&amp;amp; typeof module !== &amp;#039;undefined&amp;#039; ? factory(exports) :&lt;br /&gt;
    typeof define === &amp;#039;function&amp;#039; &amp;amp;&amp;amp; define.amd ? define(&amp;#039;HanAssist&amp;#039;, [&amp;#039;exports&amp;#039;], factory) :&lt;br /&gt;
    (global = typeof globalThis !== &amp;#039;undefined&amp;#039; ? globalThis : global || self, factory((global.mw = global.mw || {}, global.mw.libs = global.mw.libs || {}, global.mw.libs.HanAssist = {})));&lt;br /&gt;
})(this, (function (exports) { &amp;#039;use strict&amp;#039;;&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Safely convert an object to string.&lt;br /&gt;
     * @param val value to convert&lt;br /&gt;
     * @return string&lt;br /&gt;
     */&lt;br /&gt;
    function safelyToString(val) {&lt;br /&gt;
        try {&lt;br /&gt;
            if (typeof val === &amp;#039;undefined&amp;#039; || val === null) {&lt;br /&gt;
                return &amp;#039;&amp;#039;;&lt;br /&gt;
            }&lt;br /&gt;
            // eslint-disable-next-line @typescript-eslint/no-base-to-string&lt;br /&gt;
            return String(val);&lt;br /&gt;
        }&lt;br /&gt;
        catch (_a) {&lt;br /&gt;
            return Object.prototype.toString.call(val);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    function isPlainObject(val) {&lt;br /&gt;
        return $.isPlainObject(val);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    const FALLBACK_LIST = {&lt;br /&gt;
        zh: [&amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-hans&amp;#039;: [&amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-hant&amp;#039;: [&amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-cn&amp;#039;: [&amp;#039;cn&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-sg&amp;#039;: [&amp;#039;sg&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-my&amp;#039;: [&amp;#039;my&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-tw&amp;#039;: [&amp;#039;tw&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-hk&amp;#039;: [&amp;#039;hk&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
        &amp;#039;zh-mo&amp;#039;: [&amp;#039;mo&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;my&amp;#039;, &amp;#039;other&amp;#039;],&lt;br /&gt;
    };&lt;br /&gt;
    const DEFAULT_FALLBACK = [&amp;#039;other&amp;#039;, &amp;#039;zh&amp;#039;, &amp;#039;hans&amp;#039;, &amp;#039;hant&amp;#039;, &amp;#039;cn&amp;#039;, &amp;#039;tw&amp;#039;, &amp;#039;hk&amp;#039;, &amp;#039;sg&amp;#039;, &amp;#039;mo&amp;#039;, &amp;#039;my&amp;#039;];&lt;br /&gt;
    function elect(candidates, locale) {&lt;br /&gt;
        var _a;&lt;br /&gt;
        const fallback = (_a = FALLBACK_LIST[locale]) !== null &amp;amp;&amp;amp; _a !== undefined ? _a : DEFAULT_FALLBACK;&lt;br /&gt;
        // Try every locale sequently&lt;br /&gt;
        for (const key of fallback) {&lt;br /&gt;
            const value = candidates[key];&lt;br /&gt;
            // Return if the value is neither null nor undefined&lt;br /&gt;
            if (value != null) {&lt;br /&gt;
                return value;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return null;&lt;br /&gt;
    }&lt;br /&gt;
    function preprocessLocale(locale) {&lt;br /&gt;
        if (locale == null) {&lt;br /&gt;
            mw.log.warn(&amp;#039;[HanAssist] locale parameter is null-ish. Defaulting to wgUserLanguage.&amp;#039;);&lt;br /&gt;
            return mw.config.get(&amp;#039;wgUserLanguage&amp;#039;);&lt;br /&gt;
        }&lt;br /&gt;
        if (typeof locale !== &amp;#039;string&amp;#039;) {&lt;br /&gt;
            mw.log.warn(&amp;#039;[HanAssist] locale parameter must be a string. Please check your code.&amp;#039;);&lt;br /&gt;
            return safelyToString(locale);&lt;br /&gt;
        }&lt;br /&gt;
        return locale;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * A wrapper around `elect()` to ensure no non-string results are returned.&lt;br /&gt;
     */&lt;br /&gt;
    function safeElect(candidates, locale) {&lt;br /&gt;
        var _a;&lt;br /&gt;
        // Guards to ensure types at runtime&lt;br /&gt;
        if (!isPlainObject(candidates)) {&lt;br /&gt;
            throw new TypeError(&amp;#039;[HanAssist] Invalid parameter. Must be an object.&amp;#039;);&lt;br /&gt;
        }&lt;br /&gt;
        locale = preprocessLocale(locale);&lt;br /&gt;
        const result = (_a = elect(candidates, locale)) !== null &amp;amp;&amp;amp; _a !== undefined ? _a : &amp;#039;&amp;#039;;&lt;br /&gt;
        if (typeof result !== &amp;#039;string&amp;#039;) {&lt;br /&gt;
            mw.log.warn(&amp;#039;[HanAssist] Non-string conversion result detected. Please check your code.&amp;#039;);&lt;br /&gt;
        }&lt;br /&gt;
        // Wrap in another guard to ensure result is really string at runtime&lt;br /&gt;
        return safelyToString(result);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Select between candidates based on user language.&lt;br /&gt;
     * @param candidates an object of candidates&lt;br /&gt;
     * @param locale locale, defaults to `wgUserLanguage`&lt;br /&gt;
     * @returns selected value&lt;br /&gt;
     */&lt;br /&gt;
    function conv(candidates, locale = mw.config.get(&amp;#039;wgUserLanguage&amp;#039;)) {&lt;br /&gt;
        return safeElect(candidates, locale);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Select between candidates based on user variant.&lt;br /&gt;
     * @param candidates an object of candidates&lt;br /&gt;
     * @returns selected value&lt;br /&gt;
     */&lt;br /&gt;
    function convByVar(candidates) {&lt;br /&gt;
        var _a, _b;&lt;br /&gt;
        return safeElect(candidates, (_b = (_a = mw.config.get(&amp;#039;wgUserVariant&amp;#039;)) !== null &amp;amp;&amp;amp; _a !== undefined ? _a : new URL(location.href).searchParams.get(&amp;#039;variant&amp;#039;)) !== null &amp;amp;&amp;amp; _b !== undefined ? _b : mw.user.options.get(&amp;#039;variant&amp;#039;));&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Perform selection for each item in a candidates dictionary.&lt;br /&gt;
     * @param candidatesDict the dictionary of candidates&lt;br /&gt;
     * @param locale locale, defaults to `wgUserLanguage`&lt;br /&gt;
     * @returns converted candidates dictionary&lt;br /&gt;
     */&lt;br /&gt;
    function batchConv(candidatesDict, locale = mw.config.get(&amp;#039;wgUserLanguage&amp;#039;)) {&lt;br /&gt;
        var _a;&lt;br /&gt;
        if (!isPlainObject(candidatesDict)) {&lt;br /&gt;
            throw new TypeError(&amp;#039;[HanAssist] Invalid parameter. Must be an object.&amp;#039;);&lt;br /&gt;
        }&lt;br /&gt;
        locale = preprocessLocale(locale);&lt;br /&gt;
        const result = {};&lt;br /&gt;
        for (const key in candidatesDict) {&lt;br /&gt;
            const candidates = candidatesDict[key];&lt;br /&gt;
            if (isPlainObject(candidates)) {&lt;br /&gt;
                const electResult = (_a = elect(candidates, locale)) !== null &amp;amp;&amp;amp; _a !== undefined ? _a : &amp;#039;&amp;#039;;&lt;br /&gt;
                if (typeof electResult !== &amp;#039;string&amp;#039;) {&lt;br /&gt;
                    mw.log.warn(`[HanAssist] In &amp;#039;${key}&amp;#039;: Non-string conversion result detected. Please check your code.`);&lt;br /&gt;
                }&lt;br /&gt;
                result[key] = safelyToString(electResult);&lt;br /&gt;
            }&lt;br /&gt;
            else {&lt;br /&gt;
                if (typeof candidates !== &amp;#039;string&amp;#039;) {&lt;br /&gt;
                    mw.log.warn(`[HanAssist] In &amp;#039;${key}&amp;#039;: Value is neither a candidate list nor a string. Please check your code.`);&lt;br /&gt;
                }&lt;br /&gt;
                result[key] = safelyToString(candidates);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    {&lt;br /&gt;
        void Promise.resolve().then(function () { return shims; });&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    function uxsShim(locale, hans, hant, cn, tw, hk, sg, zh, mo, my) {&lt;br /&gt;
        try {&lt;br /&gt;
            return elect({&lt;br /&gt;
                hans, hant, cn, tw, hk, sg, zh, mo, my,&lt;br /&gt;
            }, locale);&lt;br /&gt;
        }&lt;br /&gt;
        catch (_a) {&lt;br /&gt;
            return undefined;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    function generateUxsShim(configName) {&lt;br /&gt;
        return (hans, hant, cn, tw, hk, sg, zh, mo, my) =&amp;gt; uxsShim(mw.config.get(configName), hans, hant, cn, tw, hk, sg, zh, mo, my);&lt;br /&gt;
    }&lt;br /&gt;
    // eslint-disable-next-line @typescript-eslint/no-explicit-any&lt;br /&gt;
    function deprecate(root, name, func, replacement) {&lt;br /&gt;
        mw.log.deprecate(root, name, func, `Use ${replacement} instead. See [[Wikipedia:HanAssist]] for more information.`);&lt;br /&gt;
    }&lt;br /&gt;
    // Compatibility: redirect wgULS, wgUVS and wgUXS calls to HanAssist implementation&lt;br /&gt;
    deprecate(self, &amp;#039;wgULS&amp;#039;, generateUxsShim(&amp;#039;wgUserLanguage&amp;#039;), &amp;#039;HanAssist.conv&amp;#039;);&lt;br /&gt;
    deprecate(self, &amp;#039;wgUVS&amp;#039;, generateUxsShim(&amp;#039;wgUserVariant&amp;#039;), &amp;#039;HanAssist.convByVar&amp;#039;);&lt;br /&gt;
    deprecate(self, &amp;#039;wgUXS&amp;#039;, uxsShim, &amp;#039;HanAssist.conv&amp;#039;);&lt;br /&gt;
    // Compatibility: redirect HanAssist &amp;lt;= v3 calls to v4&lt;br /&gt;
    const globalMountPoint = (mw.libs.HanAssist = mw.libs.HanAssist || {});&lt;br /&gt;
    deprecate(globalMountPoint, &amp;#039;localize&amp;#039;, conv, &amp;#039;conv&amp;#039;);&lt;br /&gt;
    deprecate(globalMountPoint, &amp;#039;vary&amp;#039;, convByVar, &amp;#039;convByVar&amp;#039;);&lt;br /&gt;
    deprecate(globalMountPoint, &amp;#039;parse&amp;#039;, batchConv, &amp;#039;batchConv&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
    var shims = /*#__PURE__*/Object.freeze({&lt;br /&gt;
        __proto__: null&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    exports.batchConv = batchConv;&lt;br /&gt;
    exports.conv = conv;&lt;br /&gt;
    exports.convByVar = convByVar;&lt;br /&gt;
&lt;br /&gt;
}));&lt;br /&gt;
// &amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>鹿野耕云</name></author>
	</entry>
</feed>