Simplified Chinese Characters For Wiktionary

When using the English Wiktionary, the search for Simplified Chinese Characters will always suggest the user to navigate to the corresponding Traditional Chinese Characters page. So we automatically redirect the user.

  1. // ==UserScript==
  2. // @name Simplified Chinese Characters For Wiktionary
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description When using the English Wiktionary, the search for Simplified Chinese Characters will always suggest the user to navigate to the corresponding Traditional Chinese Characters page. So we automatically redirect the user.
  6. // @author moraesvic
  7. // @source https://gist.github.com/moraesvic/5a8ff36c17fcd3feace5c5d6369c5583
  8. // @match http*://*.wiktionary.org/*
  9. // @license GNU GPLv3
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /**
  14. * This script has been published to Greasy Fork镜像 at
  15. * https://gf.qytechs.cn/en/scripts/484991-simplified-chinese-characters-for-wiktionary
  16. *
  17. * It can be added as a user script to browsers like Firefox and Chrome, by adding it to a browser extension
  18. * like TamperMonkey, GreaseMonkey, or ViolentMonkey.
  19. */
  20.  
  21. "use strict";
  22.  
  23. const DEBUG = true;
  24.  
  25. const debug = (...args) => {
  26. if (DEBUG) {
  27. console.debug("[simplified-chinese]", ...args);
  28. }
  29. };
  30.  
  31. /**
  32. * @param {string} x
  33. */
  34. const $$ = (x) => Array.from(document.querySelectorAll(x));
  35.  
  36. /**
  37. * @param {Document} document The current value of `document`
  38. * @returns {boolean}
  39. */
  40. const hasChineseEntry = (document) => {
  41. return document.querySelector("#Chinese") !== null;
  42. };
  43.  
  44. /**
  45. * @param {Document} document The current value of `document`
  46. * @returns {string | null}
  47. */
  48. const getNewHref = (document) => {
  49. debug("Starting.");
  50.  
  51. if (!hasChineseEntry(document)) {
  52. debug("Page has no entry for Chinese, leaving.");
  53. return null;
  54. }
  55.  
  56. const href = $$("i")
  57. .find((x) => x.innerHTML.startsWith("This term is the simplified form of"))
  58. ?.nextElementSibling?.querySelector("a")?.href;
  59.  
  60. if (href === undefined) {
  61. debug("Can't find traditional form, leaving.");
  62. return null;
  63. }
  64.  
  65. return href;
  66. };
  67.  
  68. const main = () => {
  69. const href = getNewHref(document);
  70.  
  71. if (href === null) {
  72. return;
  73. }
  74.  
  75. debug("Assigning new location", href);
  76. location.assign(href);
  77. };
  78.  
  79. main();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址