Commit 4ce2d6caf1d03a2b33ebd4549300eac18c0df239
1 parent
8d9aec3d
Exists in
master
Adds encode uri
Showing
2 changed files
with
41 additions
and
44 deletions
Show diff stats
chrome/app/main.js
| 1 | var app = { | 1 | var app = { |
| 2 | - chooser: null, | ||
| 3 | - glosa: undefined, | ||
| 4 | - loaded: false, | ||
| 5 | - lastReq: { | ||
| 6 | - url: null, | ||
| 7 | - millis: null, | ||
| 8 | - response: null | ||
| 9 | - } | 2 | + chooser: null, |
| 3 | + glosa: undefined, | ||
| 4 | + loaded: false, | ||
| 5 | + lastReq: { | ||
| 6 | + url: null, | ||
| 7 | + millis: null, | ||
| 8 | + response: null | ||
| 9 | + } | ||
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | function onLoadPlayer() { | 12 | function onLoadPlayer() { |
| 13 | - if ( app.glosa !== undefined ) { | ||
| 14 | - SendMessage('PlayerManager', 'catchGlosa', app.glosa); | ||
| 15 | - } | 13 | + if ( app.glosa !== undefined ) |
| 14 | + SendMessage('PlayerManager', 'catchGlosa', app.glosa); | ||
| 16 | 15 | ||
| 17 | - app.loaded = true; | 16 | + app.loaded = true; |
| 18 | } | 17 | } |
| 19 | 18 | ||
| 20 | chrome.runtime.onMessage.addListener( | 19 | chrome.runtime.onMessage.addListener( |
| 21 | - function(request, sender, sendResponse) { | ||
| 22 | - if (request.selectedText === undefined) return; | ||
| 23 | - | ||
| 24 | - app.chooser = app.chooser || new qdClient.Chooser(); | ||
| 25 | - | ||
| 26 | - document.getElementById('loading-screen').style.display = 'block'; | ||
| 27 | - app.chooser.choose( | ||
| 28 | - app.lastReq.url, | ||
| 29 | - app.lastReq.millis, | ||
| 30 | - app.lastReq.response, | ||
| 31 | - function (url) { | ||
| 32 | - var start = new Date().getTime(); | ||
| 33 | - | ||
| 34 | - console.log('Url selected: ' + url); | ||
| 35 | - qdClient.request(url + '?texto=' + request.selectedText, "GET", {}, | ||
| 36 | - function(status, response) { | ||
| 37 | - app.lastReq.response = status === 404 ? -1 : status; | ||
| 38 | - app.lastReq.millis = (new Date().getTime() - start); | ||
| 39 | - app.lastReq.url = url; | ||
| 40 | - | ||
| 41 | - app.glosa = response; | ||
| 42 | - | ||
| 43 | - document.getElementById('loading-screen').style.display = 'none'; | ||
| 44 | - if (app.loaded == true) { | ||
| 45 | - SendMessage('PlayerManager', 'catchGlosa', app.glosa); | ||
| 46 | - } | 20 | + function(request, sender, sendResponse) { |
| 21 | + if (request.selectedText === undefined) return; | ||
| 22 | + | ||
| 23 | + request.selectedText = encodeURI(request.selectedText); | ||
| 24 | + | ||
| 25 | + app.chooser = app.chooser || new qdClient.Chooser(); | ||
| 26 | + | ||
| 27 | + document.getElementById('loading-screen').style.display = 'block'; | ||
| 28 | + app.chooser.choose( | ||
| 29 | + app.lastReq.url, | ||
| 30 | + app.lastReq.millis, | ||
| 31 | + app.lastReq.response, | ||
| 32 | + function (url) { | ||
| 33 | + var start = new Date().getTime(); | ||
| 34 | + qdClient.request(url + '?texto=' + request.selectedText, "GET", {}, | ||
| 35 | + function(status, response) { | ||
| 36 | + app.lastReq.response = status === 404 ? -1 : status; | ||
| 37 | + app.lastReq.millis = (new Date().getTime() - start); | ||
| 38 | + app.lastReq.url = url; | ||
| 39 | + | ||
| 40 | + app.glosa = response; | ||
| 41 | + | ||
| 42 | + if (app.loaded == true) | ||
| 43 | + SendMessage('PlayerManager', 'catchGlosa', app.glosa); | ||
| 44 | + | ||
| 45 | + document.getElementById('loading-screen').style.display = 'none'; | ||
| 47 | }); | 46 | }); |
| 48 | }); | 47 | }); |
| 49 | }); | 48 | }); |
firefox/data/main.js
| @@ -10,11 +10,8 @@ var app = { | @@ -10,11 +10,8 @@ var app = { | ||
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | function onLoadPlayer() { | 12 | function onLoadPlayer() { |
| 13 | - console.log(app.glosa); | ||
| 14 | - | ||
| 15 | - if ( app.glosa !== undefined ) { | 13 | + if ( app.glosa !== undefined ) |
| 16 | SendMessage('PlayerManager', 'catchGlosa', app.glosa); | 14 | SendMessage('PlayerManager', 'catchGlosa', app.glosa); |
| 17 | - } | ||
| 18 | 15 | ||
| 19 | app.loaded = true; | 16 | app.loaded = true; |
| 20 | } | 17 | } |
| @@ -22,6 +19,8 @@ function onLoadPlayer() { | @@ -22,6 +19,8 @@ function onLoadPlayer() { | ||
| 22 | document.addEventListener('plugin:selectedText', function(e) { | 19 | document.addEventListener('plugin:selectedText', function(e) { |
| 23 | if (e.detail === undefined) return; | 20 | if (e.detail === undefined) return; |
| 24 | 21 | ||
| 22 | + e.detail = encodeURI(e.detail); | ||
| 23 | + | ||
| 25 | app.chooser = app.chooser || new qdClient.Chooser(); | 24 | app.chooser = app.chooser || new qdClient.Chooser(); |
| 26 | 25 | ||
| 27 | document.getElementById('loading-screen').style.display = 'block'; | 26 | document.getElementById('loading-screen').style.display = 'block'; |
| @@ -41,9 +40,8 @@ document.addEventListener('plugin:selectedText', function(e) { | @@ -41,9 +40,8 @@ document.addEventListener('plugin:selectedText', function(e) { | ||
| 41 | app.glosa = response; | 40 | app.glosa = response; |
| 42 | 41 | ||
| 43 | document.getElementById('loading-screen').style.display = 'none'; | 42 | document.getElementById('loading-screen').style.display = 'none'; |
| 44 | - if (app.loaded == true) { | 43 | + if (app.loaded == true) |
| 45 | SendMessage('PlayerManager', 'catchGlosa', app.glosa); | 44 | SendMessage('PlayerManager', 'catchGlosa', app.glosa); |
| 46 | - } | ||
| 47 | }); | 45 | }); |
| 48 | }); | 46 | }); |
| 49 | }); | 47 | }); |