Greasy Fork 还支持 简体中文。

IPA

text to ipa

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        IPA
// @namespace   http://www.olivetti.info
// @description text to ipa
// @include     *
// @version     1
// @grant    GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// ==/UserScript==

function doMonkey(){
   work(false,"words.json");
}
function doMonkey2(){
   work(true,"words.json");
}

function doMonkey3(){
   work(false,"wordsAmE.json");
}
function doMonkey4(){
   work(true,"wordsAmE.json");
}
  
function work(remove,dict){
  GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://www.olivetti.info/'+dict,
    onload: function (response) {
      dataReady(response.responseText, remove);
    }
  });
}
function dataReady(text,remove) {
  words = JSON.parse(text);
  function replaceIpaString(s) {
    if (s.length == 0) return '';
    var delim = ' ,.;:<>()\n!\"—'.split('');
    var p = - 1;
    for (var i = 0; i < delim.length; i++) {
      var p2 = s.indexOf(delim[i]);
      if (p2 != - 1 && (p == - 1 || p2 < p)) p = p2;
    }
    if (p == 0) return s.charAt(0) + replaceIpaString(s.substring(1));
    var word = s;
    if (p != - 1) word = s.substring(0, p);
    var ipaword = words[word];
    var skip = word.length;
    if (ipaword !== undefined){
       if(remove)ipaword = ipaword.replace(/[.ˈ]/g,'').replace(/[(]r[)]/g,'').replace(/[ˌ]/g,'');
       word = ipaword;
    } 
    return word + replaceIpaString(s.substring(skip));
  }
  function replaceIpa(n) {
    var m;
    if (n.nodeType == 3) { // TEXT_NODE 
      var sp = n.parentNode.nodeName.toLowerCase();
      if( sp != "style" && sp != "script" ){
        ns = replaceIpaString(n.data.toLowerCase());
        n.data = ns;
      }
    } 
    else if (n.nodeType == 1) { // ELEMENT_NODE 
      for (m = n.firstChild; null != m; m = m.nextSibling) {
        replaceIpa(m);
      }
    }
  }
  replaceIpa(document.body);
}

GM_registerMenuCommand( "Convert EN", doMonkey);
GM_registerMenuCommand( "Convert EN clean", doMonkey2);
GM_registerMenuCommand( "Convert US", doMonkey3);
GM_registerMenuCommand( "Convert US clean", doMonkey4);