IPA

text to ipa

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);