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)
{
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.runtime.onMessage.addListener(()=>{
browser.runtime.onMessage.addListener((message)=>{
if(message === "Button_clicked")
{
nextUrl(data,tab,i);
console.log("pass tab data to run, in promise");
console.log(tab);
}
});
});
});
}
});
function failure(value)
{
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)
{
let count_urls = data.subscriptions.length;
@ -42,13 +37,27 @@ async function nextUrl(data,tab,i)
await sendMessageToContent(data,tab,i);
code1 = `window.location.replace("${data.subscriptions[i].url}");`
console.log(code1);
await browser.tabs.update(tab.tabid,{url : data.subscriptions[i].url});
console.log(tab);
console.log("iterating");
console.log(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)
{
return new Promise(resolve => {
@ -58,6 +67,7 @@ function sendMessageToContent(data,tab,i)
})
.then(function() {
console.log("background.js: received start signal...");
console.log("backgroundscript received start signal from contentscript");
if(i == 0)
{
browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url})

View File

@ -4,7 +4,7 @@
"version": "1.0",
"description": "---",
"web_accessible_resources":["newpipe_subscriptions_202403101004.json"],
"permissions":["activeTab","<all_urls>"],
"permissions":["activeTab","<all_urls>","tabs"],
"icons": {
"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(){
window.location.replace(url);
});*/