works until loading page

This commit is contained in:
Jonathan Wyss 2024-03-17 14:40:01 +01:00
parent fee1b77f1c
commit 3a148716b2
4 changed files with 28 additions and 34 deletions

View File

@ -29,26 +29,25 @@ function failure(value)
console.log("tabs.create returned a failure"); console.log("tabs.create returned a failure");
} }
async function run(data,tab) function run(data,tab)
{ {
let i2=0; let i2=0;
// injectScript(tab); // injectScript(tab);
await browser.scripting.executeScript({ let promise = browser.tabs.executeScript(tab.id,{
target:{ file:"spawn.js"
tabId: tab.id
},
files:["spawn.js"]
}); });
promise.then(function() {
console.log("bbackground.js: received start signal..."); console.log("bbackground.js: received start signal...");
if(i2 == 0) if(i2 == 0)
{ {
browser.runtime.sendMessage({state: "Init",url: data.subscriptions[0].url}); browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url});
} }
else else
{ {
browser.runtime.sendMessage({state: i2,url: data.subscriptions[i2].url}); browser.tabs.sendMessage(tab.id,{state: i2,url: data.subscriptions[i2].url});
} }
i2++; i2++;
});
} }
function readUrl() function readUrl()

View File

@ -1,13 +1,13 @@
window.onload = run; //window.onload = run;
function run() //function run()
{ //{
document.getElementById("id_run").addEventListener("click", function(e){ document.getElementById("id_run").addEventListener("click", function(e){
console.log("triggered!!"); console.log("triggered!!");
alert("judihudi"); alert("judihudi");
startBackgroundScript(); startBackgroundScript();
e.preventDefault(); e.preventDefault();
}); });
} //}
function startBackgroundScript() function startBackgroundScript()

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":["tabs","scripting"], "permissions":["activeTab","<all_urls>"],
"icons": { "icons": {
"48": "icons/border-48.png" "48": "icons/border-48.png"
}, },
@ -21,7 +21,7 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": [ "matches": [
"*://youtube.com/*" "<all_urls>"
], ],
"js": [ "js": [
"spawn.js" "spawn.js"

View File

@ -2,7 +2,7 @@
//1.grant host permission //1.grant host permission
// //
// //
browser.runtime.onMessage.addListener(() => browser.runtime.onMessage.addListener((message) =>
{ {
console.log("inside handler"); console.log("inside handler");
if(message.state != "Init")//on init only load page if(message.state != "Init")//on init only load page
@ -16,8 +16,3 @@ console.log("inside handler");
}); });
//if(number>0)
function handle(message)
{
// window.location = url;
}