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
+ | cvox.InjectedScriptLoader.fetchCode = function(files, done) {
+ var code = {};
+ var waiting = files.length;
+ var loadScriptAsCode = function(src) {
+ var xhr = new XMLHttpRequest();
+ var url = chrome.extension.getURL(src) + '?' + new Date().getTime();
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ var scriptText = xhr.responseText;
+ ...
+ code[src] = scriptText;
+ waiting--;
+ if (waiting == 0) {
+ done(code);
+ }
+ }
+ };
+ xhr.open('GET', url);
+ xhr.send(null);
+ };
+ files.forEach(function(f) {
+ loadScriptAsCode(f);
+ });
+};
+
+...
+
+chrome.extension.onMessage.addListener(function(request, sender, callback) {
+ if (request['srcFile']) {
+ var srcFile = request['srcFile'];
+ cvox.InjectedScriptLoader.fetchCode([srcFile], function(code) {
+ callback({
+ 'code': code[srcFile]
+ });
+ });
+ }
+ return true;
+});
+ |