-
Notifications
You must be signed in to change notification settings - Fork 1
/
localserver-tts.js
68 lines (54 loc) · 1.57 KB
/
localserver-tts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(function(){
var pluginName = "localserver-tts";
var plugin = function(){
$lib = AtKit.lib();
AtKit.set('localserver_available', false);
$lib.getJSON("http://localserver.atbar.org:8451/ping?callback=?", function(data){
console.log(data);
AtKit.set('localserver_available', true);
});
// Add functions to AtKit.
AtKit.addFn('getSelectedText', function(strip){
var text = '';
if (window.getSelection){
text = window.getSelection();
} else if (document.getSelection){
text = document.getSelection();
} else if (document.selection){
text = document.selection.createRange().text;
}
if(strip == true){
return String(text).replace(/([\s]+)/ig, '');
} else {
return String(text);
}
});
AtKit.addButton(
'TTS',
"Start TTS",
AtKit.getPluginURL() + 'images/sound.png',
function(dialogs, functions){
$lib.getJSON("http://localserver.atbar.org:8451/TTS?text=" + AtKit.call('getSelectedText') + "&callback=?", function(data){
console.log(data);
});
}
);
}
if(typeof window['AtKit'] == "undefined"){
window.AtKitLoaded = function(){
var eventAction = null;
this.subscribe = function(fn) {
eventAction = fn;
};
this.fire = function(sender, eventArgs) {
if (eventAction != null) {
eventAction(sender, eventArgs);
}
};
}
window['AtKitLoaded'] = new AtKitLoaded();
window['AtKitLoaded'].subscribe(function(){ AtKit.registerPlugin(pluginName, plugin); });
} else {
AtKit.registerPlugin(pluginName, plugin);
}
})();