This commit is contained in:
ccppi 2024-03-18 11:17:23 +01:00
parent 0cc3893be9
commit 68514f7f68
3 changed files with 58 additions and 42 deletions

View File

@ -8,33 +8,28 @@ readUrl();
function Setup(data) function Setup(data)
{ {
let i=0; let i=0;
browser.browserAction.onClicked.addListener(() => { browser.browserAction.onClicked.addListener(create);
}
var create = (function(data){
let i=0;
browser.tabs.create({"url": "home.html"},function(tab){ browser.tabs.create({"url": "home.html"},function(tab){
browser.runtime.onMessage.addListener(()=>{ browser.runtime.onMessage.addListener((message)=>{
nextUrl(data,tab,i); if(message === "Button_clicked")
console.log("pass tab data to run, in promise"); {
console.log(tab); nextUrl(data,tab,i);
console.log("pass tab data to run, in promise");
console.log(tab);
}
}); });
}); });
});
});
}
function failure(value) function failure(value)
{ {
console.log("tabs.create returned a failure"); console.log("tabs.create returned a failure");
} }
function run(data,tab)
{
let i2=0;
sendMessageToContent(data,tab,i2);
// injectScript(tab);
//nextUrl()
}
async function nextUrl(data,tab,i) async function nextUrl(data,tab,i)
{ {
let count_urls = data.subscriptions.length; let count_urls = data.subscriptions.length;
@ -42,13 +37,27 @@ async function nextUrl(data,tab,i)
await sendMessageToContent(data,tab,i); await sendMessageToContent(data,tab,i);
code1 = `window.location.replace("${data.subscriptions[i].url}");` code1 = `window.location.replace("${data.subscriptions[i].url}");`
console.log(code1); console.log(code1);
await browser.tabs.update(tab.tabid,{url : data.subscriptions[i].url}); await browser.tabs.update(tab.tabid,{url : data.subscriptions[i].url});
console.log(tab);
console.log("iterating"); console.log("iterating");
console.log(i); console.log(i);
i++; i++;
} }
} }
function waitforTab(tab,url)
{
return new Promise(resolve =>{
setTimeout(() => {
console.log(tab.url);
if(tab.url === url){
console.log("Resolved wait for tab)");
resolve();
}
},5000);
});
}
function sendMessageToContent(data,tab,i) function sendMessageToContent(data,tab,i)
{ {
return new Promise(resolve => { return new Promise(resolve => {
@ -57,24 +66,25 @@ function sendMessageToContent(data,tab,i)
file:"spawn.js" file:"spawn.js"
}) })
.then(function() { .then(function() {
console.log("background.js: received start signal..."); console.log("background.js: received start signal...");
if(i == 0) console.log("backgroundscript received start signal from contentscript");
{ if(i == 0)
browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url}) {
.then((response) => { browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url})
console.log("got response!! content should reload"); .then((response) => {
console.log(response); console.log("got response!! content should reload");
resolve(); console.log(response);
}); resolve();
} });
else }
{ else
browser.tabs.sendMessage(tab.id,{state: i,url: data.subscriptions[i].url}) {
.then((response) => { browser.tabs.sendMessage(tab.id,{state: i,url: data.subscriptions[i].url})
console.log(response); .then((response) => {
resolve(); console.log(response);
}); resolve();
} });
}
}); });
}); });
} }

View File

@ -4,7 +4,7 @@
"version": "1.0", "version": "1.0",
"description": "---", "description": "---",
"web_accessible_resources":["newpipe_subscriptions_202403101004.json"], "web_accessible_resources":["newpipe_subscriptions_202403101004.json"],
"permissions":["activeTab","<all_urls>"], "permissions":["activeTab","<all_urls>","tabs"],
"icons": { "icons": {
"48": "icons/border-48.png" "48": "icons/border-48.png"
}, },

View File

@ -3,8 +3,14 @@
// //
// //
browser.runtime.onMessage.addListener(worker);
// return Promise.resolve(true); document.addEventListener("DOMContentLoaded",function(){
browser.runtime.sendMessage("Content_Loaded");
});
browser.runtime.onMessage.addListener(worker);
// return Promise.resolve(true);
/*.then(function(){ /*.then(function(){
window.location.replace(url); window.location.replace(url);
});*/ });*/