IPA Pronunciation Linker

Automatically link IPA pronunciations to a tool to pronounce them

  1. // ==UserScript==
  2. // @name IPA Pronunciation Linker
  3. // @description Automatically link IPA pronunciations to a tool to pronounce them
  4. // @author Matthew Miner
  5. // @version 1.0
  6. // @namespace https://matthewminer.name
  7. // @copyright 2022, Matthew Miner (https://matthewminer.name)
  8. // @license MIT
  9. // @homepageURL https://github.com/mminer237/ipa-pronunciation-linker/
  10. // @supportURL https://github.com/mminer237/ipa-pronunciation-linker/issues
  11. // @match https://*.wiktionary.org/wiki/*
  12. // @match https://*.wikipedia.org/wiki/*
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (() => {
  17. "use strict";
  18.  
  19. document.querySelectorAll("span.IPA").forEach(span => {
  20. /* Parse the IPA pronunciation */
  21. let text = span.textContent.match(/[\/\[](?<text>.+)[\/\]]/)?.groups.text;
  22.  
  23. /* Select voice */
  24. const voice = 'Joey';
  25.  
  26. if (text) {
  27. /* Replace non-standard IPA characters */
  28. text = text.normalize('NFD');
  29. text = text.replace(/a[\u0300-\u0307\u0309-\u031c\u031f-\u036f]/gu, 'a');
  30. text = text.replace(/e[\u0300-\u031c\u031f-\u036f]/gu, 'e');
  31. text = text.replace(/i[\u0300-\u031c\u031f-\u036f]/gu, 'i');
  32. text = text.replace(/o[\u0300-\u031c\u031f-\u036f]/gu, 'o');
  33. text = text.replace(/u[\u0300-\u031c\u031f-\u036f]/gu, 'u');
  34.  
  35. /* Insert link */
  36. span.innerHTML = `<a href="http://ipa-reader.xyz/?text=${text}&voice=${voice}" target="_blank">${span.innerText}</a>`;
  37. }
  38. });
  39. })();

QingJ © 2025

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