async functions working

This commit is contained in:
Jonathan Wyss 2024-03-17 00:40:33 +01:00
parent e8b0022302
commit 2485aab123
4 changed files with 40 additions and 16 deletions

View File

@ -1,17 +1,27 @@
let backgroundPage = browser.extension.getBackgroundPage();
//let tab;
const pass_data = {urls:"urls",tab:"tab_id"}
readUrl();
//on addon click load extension page
//
function Setup(data)
{
let promise;
browser.browserAction.onClicked.addListener(() => {
let promise = browser.tabs.create({"url": "home.html"});
// promise.then((value) => run(value),()=> failure(value));
promise = browser.tabs.create({"url": "home.html"},function(tab){
browser.runtime.onMessage.addListener(()=>{
run(data,tab);
console.log("pass tab data to run, in promise");
console.log(tab);
});
browser.runtime.onMessage.addListener(()=>run(data));
});
});
}
function failure(value)
@ -19,9 +29,16 @@ function failure(value)
console.log("tabs.create returned a failure");
}
function run(data)
async function run(data,tab)
{
let i2=0;
// injectScript(tab);
await browser.scripting.executeScript({
target:{
tabId: tab.id
},
files:["spawn.js"]
});
console.log("bbackground.js: received start signal...");
if(i2 == 0)
{
@ -63,3 +80,4 @@ function readUrl()
}

View File

@ -4,7 +4,7 @@
"version": "1.0",
"description": "---",
"web_accessible_resources":["newpipe_subscriptions_202403101004.json"],
"permissions":["tabs"],
"permissions":["tabs","scripting"],
"icons": {
"48": "icons/border-48.png"
},
@ -16,6 +16,7 @@
},
"background":{
"scripts": ["background.js"]
}
},
"host_permissions":["*://youtube.com/*"]
}

View File

@ -2,17 +2,22 @@
//1.grant host permission
//
//
browser.runtime.onMessage.addListener((message,listener,handle)
browser.runtime.onMessage.addListener(function (message,listener)
{
handle(message);
});
//if(number>0)
function handle()
function handle(message)
{
if(message != 0)//on init only load page
console.log("inside handler");
if(message.state != "Init")//on init only load page
{
document.getElementsByClassName("yt-spec-button-shape-next yt-spec-button-shape-next--filled yt-spec-button-shape-next--mono yt-spec-button-shape-next--size-m")[0].click();
console.log(message);
}
let url = message;
window.location.replace(url);
let url = message.url;
console.log(url);
window.location.replace(url);
// window.location = url;
}