main.js
1.17 KB
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
var app = {
chooser: null,
glosa: undefined,
loaded: false,
lastReq: {
url: null,
millis: null,
response: null
}
};
function onLoadPlayer() {
console.log(app.glosa);
if ( app.glosa !== undefined ) {
SendMessage('PlayerManager', 'catchGlosa', app.glosa);
}
app.loaded = true;
}
document.addEventListener('plugin:selectedText', function(e) {
if (e.detail === undefined) return;
app.chooser = app.chooser || new qdClient.Chooser();
document.getElementById('loading-screen').style.display = 'block';
app.chooser.choose(
app.lastReq.url,
app.lastReq.millis,
app.lastReq.response,
function (url) {
var start = new Date().getTime();
qdClient.request(url + '?texto=' + e.detail, "GET", {},
function(status, response) {
app.lastReq.response = status === 404 ? -1 : status;
app.lastReq.millis = (new Date().getTime() - start);
app.lastReq.url = url;
app.glosa = response;
document.getElementById('loading-screen').style.display = 'none';
if (app.loaded == true) {
SendMessage('PlayerManager', 'catchGlosa', app.glosa);
}
});
});
});