From 3a148716b28ab3e2177a48599a07c588c16d1141 Mon Sep 17 00:00:00 2001 From: Jonathan Wyss Date: Sun, 17 Mar 2024 14:40:01 +0100 Subject: [PATCH] works until loading page --- background.js | 31 +++++++++++++++---------------- home.js | 20 ++++++++++---------- manifest.json | 4 ++-- spawn.js | 7 +------ 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/background.js b/background.js index bf32a72..b253a4c 100644 --- a/background.js +++ b/background.js @@ -29,26 +29,25 @@ function failure(value) console.log("tabs.create returned a failure"); } -async function run(data,tab) +function run(data,tab) { let i2=0; // injectScript(tab); - await browser.scripting.executeScript({ - target:{ - tabId: tab.id - }, - files:["spawn.js"] + let promise = browser.tabs.executeScript(tab.id,{ + file:"spawn.js" }); - console.log("bbackground.js: received start signal..."); - if(i2 == 0) - { - browser.runtime.sendMessage({state: "Init",url: data.subscriptions[0].url}); - } - else - { - browser.runtime.sendMessage({state: i2,url: data.subscriptions[i2].url}); - } - i2++; + promise.then(function() { + console.log("bbackground.js: received start signal..."); + if(i2 == 0) + { + browser.tabs.sendMessage(tab.id,{state: "Init",url: data.subscriptions[0].url}); + } + else + { + browser.tabs.sendMessage(tab.id,{state: i2,url: data.subscriptions[i2].url}); + } + i2++; + }); } function readUrl() diff --git a/home.js b/home.js index 06c5523..da593cb 100644 --- a/home.js +++ b/home.js @@ -1,13 +1,13 @@ -window.onload = run; -function run() -{ - document.getElementById("id_run").addEventListener("click", function(e){ - console.log("triggered!!"); - alert("judihudi"); - startBackgroundScript(); - e.preventDefault(); - }); -} +//window.onload = run; +//function run() +//{ +document.getElementById("id_run").addEventListener("click", function(e){ + console.log("triggered!!"); + alert("judihudi"); + startBackgroundScript(); + e.preventDefault(); +}); +//} function startBackgroundScript() diff --git a/manifest.json b/manifest.json index 5a48a92..f34ed59 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "version": "1.0", "description": "---", "web_accessible_resources":["newpipe_subscriptions_202403101004.json"], - "permissions":["tabs","scripting"], + "permissions":["activeTab",""], "icons": { "48": "icons/border-48.png" }, @@ -21,7 +21,7 @@ "content_scripts": [ { "matches": [ - "*://youtube.com/*" + "" ], "js": [ "spawn.js" diff --git a/spawn.js b/spawn.js index fc3beb8..efac3c0 100644 --- a/spawn.js +++ b/spawn.js @@ -2,7 +2,7 @@ //1.grant host permission // // -browser.runtime.onMessage.addListener(() => +browser.runtime.onMessage.addListener((message) => { console.log("inside handler"); 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; - }