自动将 URL 中的 zh-* 语言代码替换为 zh-hans 并重定向到简体中文页面
This is a Tampermonkey userscript that automatically converts various Chinese language codes in webpage URLs to Simplified Chinese code zh-hans and redirects to the Simplified Chinese page.
zh-hk (Hong Kong), zh-tw (Taiwan), zh-hant (Traditional), zh-sg (Singapore), zh-mo (Macau), etc.zh-CN, zh-cn, and zh-hans unchangedThe script monitors all webpage URLs and automatically redirects when it detects Chinese language codes in the following formats:
zh-hk (Hong Kong Traditional)zh-tw (Taiwan Traditional)zh-hant (Traditional Chinese)zh-sg (Singapore Simplified)zh-mo (Macau Traditional)zh-* variantsThe script will replace them with zh-hans (Simplified Chinese) and redirect to the new URL.
Note: zh-CN, zh-cn, and zh-hans will not be converted as they are already Simplified Chinese codes.
The following URLs will be automatically redirected:
https://example.com/zh-tw/page → https://example.com/zh-hans/pagehttps://example.com/zh-hk/article → https://example.com/zh-hans/articlehttps://example.com/zh-hant/docs → https://example.com/zh-hans/docsURLs that won't be redirected:
https://example.com/zh-CN/page (remains unchanged)https://example.com/zh-cn/page (remains unchanged)https://example.com/zh-hans/page (remains unchanged)zh-hans language codezh-* language codes to zh-hanszh-CN, zh-cn, and zh-hans from conversionThis script is released under the MIT License and can be freely used and modified.
If you have any questions or suggestions, please leave feedback on the Greasyfork page.
/\/zh-(?!hans\b|CN\b|cn\b)([a-zA-Z]{2,4})\b/gi
/zh-: Matches /zh- in URL(?!hans\b|CN\b|cn\b): Negative lookahead to exclude hans, CN, and cn([a-zA-Z]{2,4}): Captures 2-4 letter language codes\b: Word boundary to ensure complete matchgi: Global and case-insensitive flagswindow.location.replace() for instant redirection这是一个 Tampermonkey 用户脚本,可以自动将网页 URL 中的各种中文语言代码转换为简体中文代码 zh-hans,并自动重定向到简体中文页面。
zh-hk(香港)、zh-tw(台湾)、zh-hant(繁体)、zh-sg(新加坡)、zh-mo(澳门)等变体zh-CN、zh-cn 和 zh-hans 不做转换脚本会监控所有网页的 URL,当检测到 URL 中包含以下格式的中文语言代码时:
zh-hk (香港繁体)zh-tw (台湾繁体)zh-hant (繁体中文)zh-sg (新加坡简体)zh-mo (澳门繁体)zh-* 变体脚本会自动将其替换为 zh-hans (简体中文) 并重定向到新 URL。
注意: zh-CN、zh-cn 和 zh-hans 不会被转换,因为它们已经是简体中文代码。
访问以下 URL 时会自动重定向:
https://example.com/zh-tw/page → https://example.com/zh-hans/pagehttps://example.com/zh-hk/article → https://example.com/zh-hans/articlehttps://example.com/zh-hant/docs → https://example.com/zh-hans/docs不会重定向的 URL:
https://example.com/zh-CN/page (保持不变)https://example.com/zh-cn/page (保持不变)https://example.com/zh-hans/page (保持不变)zh-hans 语言代码zh-* 语言代码为 zh-hanszh-CN、zh-cn 和 zh-hans 不做转换本脚本采用 MIT 许可证发布,可自由使用和修改。
如有问题或建议,欢迎在 Greasyfork 页面留言反馈。