-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbg.js
37 lines (33 loc) · 932 Bytes
/
bg.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
var executionInProgress = false;
var rowArray = null;
// var urlArray = null;
// var renderMethod = null;
chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.addListener(function(msg) {
if (msg.type === 'init') {
executionInProgress = true;
rowArray = msg.rawTxt.replace(/^\s+|\s+$/g, '').split("\n");
var rowTxt = rowArray.shift();
port.postMessage({
'type' : 'fetch',
'rowTxt' : rowTxt
});
} else if (msg.type === 'next') {
// next row
if (executionInProgress) {
var rowTxt = rowArray.shift();
if (rowTxt !== undefined) {
port.postMessage({
'type' : 'fetch',
'rowTxt' : rowTxt
});
} else {
executionInProgress = false; //done
rowArray = null;
}
} else {
console.log("no more rows to be processed."); //xxx
}
}
});
});