-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground-script.js
51 lines (50 loc) · 1.57 KB
/
background-script.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
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request) {
var response = grabVerse(request);
response.then(sendResponse(response));
}
});
function grabVerse(request) {
return new Promise(function(resolve, reject) {
// console.log(request)
let parsedRequest = JSON.parse(request);
//let abbObj = parsedRequest.abbObj;
let book = parsedRequest.abbObj.book;
if (book) {book = book.replace(" ", "%20");};
// let chapterStart = abbObj.chapterStart;
// let verseStart = abbObj.verseStart;
// let verseEnd = abbObj.verseEnd;
// let letter = abbObj.letter;
let charset = parsedRequest.charset;
// let startMatchString = parsedRequest.startMatchString;
// let endMatchString = parsedRequest.endMatchString;
// let endOfTextString = parsedRequest.endOfTextString;
var urlsToGet = parsedRequest.urlsToGet;
var fetchedPages = [];
var promises = [];
$.ajaxSetup({
processData: false,
beforeSend: function(jqXHR) {
jqXHR.overrideMimeType('text/html;charset=' + charset);
}
});
//console.log(urlsToGet);
for (i in urlsToGet){
promises.push(new Promise(function(resolve, reject)
{let myGet = $.get(urlsToGet[i], function(fetchedData){
fetchedPages.push(fetchedData);
//console.log(fetchedPages);
myGet.then(function () {
resolve(fetchedData);
});
// myGet.then(resolve(fetchedData));
//resolve(data);
})
}));
Promise.all(promises).then(function () {
resolve(fetchedPages);
});
}
})
}