// This work is licensed under the Creative Commons Attribution 3.0 United States License. To view | |
// a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter | |
// to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. | |
// Copyright 2009 John Tantalo <john.tantalo@gmail.com> | |
(function () { | |
// get selection | |
var selection = window.getSelection ? window.getSelection() : | |
document.getSelection ? document.getSelection() : | |
document.selection ? document.selection.createRange().text : ''; | |
// stringify selection | |
if (selection) { | |
selection = String(selection); | |
} | |
if (selection) { | |
// find IPA | |
var match = selection.match('\/(.*)\/'); | |
var ipa; | |
if (match && match[1]) { | |
ipa = match[1]; | |
} | |
if (!ipa) { | |
ipa = prompt("Couldn't find any IPA. Type it in instead?"); | |
} | |
if (ipa) { | |
// escape | |
ipa = ipa.replace(/./g, function (c) { | |
if (/%u0(...)/.test(escape(c))) { | |
return escape(c).replace(/%u0(...)/g, '&#x$1;'); | |
} else { | |
return c; | |
} | |
}); | |
// prepare request | |
var request = { | |
txt: '<phoneme alphabet="ipa" ph="'+ipa+'"> </phoneme>', | |
voice: 'crystal' | |
}; | |
// create iframe | |
var iframe = document.createElement('iframe'); | |
iframe.name = iframe.id = "iframe"+new Date().getTime(); | |
document.body.appendChild(iframe); | |
// create form | |
var form = document.createElement('form'); | |
form.target = iframe.name; | |
form.method = 'post'; | |
form.action = 'http://192.20.225.36/tts/cgi-bin/nph-nvdemo'; | |
form.acceptCharset = "iso-8859-1"; | |
form.style.display = 'none'; | |
// add parameters | |
for (var name in request) { | |
var input = document.createElement('input'); | |
input.name = name; | |
input.value = request[name]; | |
form.appendChild(input); | |
} | |
document.body.appendChild(form); | |
// submit form | |
form.submit(); | |
} | |
} else { | |
alert("Select some IPA."); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment