iterration works
This commit is contained in:
parent
3a148716b2
commit
acd94cb7ab
@ -7,13 +7,12 @@ readUrl();
|
||||
//
|
||||
function Setup(data)
|
||||
{
|
||||
let promise;
|
||||
let i=0;
|
||||
browser.browserAction.onClicked.addListener(() => {
|
||||
|
||||
promise = browser.tabs.create({"url": "home.html"},function(tab){
|
||||
|
||||
browser.tabs.create({"url": "home.html"},function(tab){
|
||||
browser.runtime.onMessage.addListener(()=>{
|
||||
run(data,tab);
|
||||
nextUrl(data,tab,i);
|
||||
console.log("pass tab data to run, in promise");
|
||||
console.log(tab);
|
||||
});
|
||||
@ -32,24 +31,49 @@ function failure(value)
|
||||
function run(data,tab)
|
||||
{
|
||||
let i2=0;
|
||||
sendMessageToContent(data,tab,i2);
|
||||
// injectScript(tab);
|
||||
let promise = browser.tabs.executeScript(tab.id,{
|
||||
file:"spawn.js"
|
||||
});
|
||||
promise.then(function() {
|
||||
console.log("bbackground.js: received start signal...");
|
||||
if(i2 == 0)
|
||||
//nextUrl()
|
||||
}
|
||||
async function nextUrl(data,tab,i)
|
||||
{
|
||||
browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url});
|
||||
let count_urls = data.subscriptions.length;
|
||||
for(i=0;i<count_urls;){
|
||||
await sendMessageToContent(data,tab,i);
|
||||
console.log("iterating");
|
||||
console.log(i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
function sendMessageToContent(data,tab,i)
|
||||
{
|
||||
return new Promise(resolve => {
|
||||
|
||||
browser.tabs.executeScript(tab.id,{
|
||||
file:"spawn.js"
|
||||
})
|
||||
.then(function() {
|
||||
console.log("background.js: received start signal...");
|
||||
if(i == 0)
|
||||
{
|
||||
browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url})
|
||||
.then((response) => {
|
||||
console.log("got response!! content should reload");
|
||||
console.log(response);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
browser.tabs.sendMessage(tab.id,{state: i2,url: data.subscriptions[i2].url});
|
||||
}
|
||||
i2++;
|
||||
browser.tabs.sendMessage(tab.id,{state: i,url: data.subscriptions[i].url})
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function readUrl()
|
||||
{
|
||||
let data;
|
||||
|
13
spawn.js
13
spawn.js
@ -2,7 +2,13 @@
|
||||
//1.grant host permission
|
||||
//
|
||||
//
|
||||
browser.runtime.onMessage.addListener((message) =>
|
||||
browser.runtime.onMessage.addListener(worker);
|
||||
|
||||
// return Promise.resolve(true);
|
||||
/*.then(function(){
|
||||
window.location.replace(url);
|
||||
});*/
|
||||
function worker(message,sender,sendResponse)
|
||||
{
|
||||
console.log("inside handler");
|
||||
if(message.state != "Init")//on init only load page
|
||||
@ -12,7 +18,6 @@ console.log("inside handler");
|
||||
}
|
||||
let url = message.url;
|
||||
console.log(url);
|
||||
sendResponse(true);
|
||||
window.location.replace(url);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user