Creating messageHandlers
This commit is contained in:
parent
2b2c21623c
commit
e8b0022302
@ -1,13 +1,65 @@
|
||||
let backgroundPage = browser.extension.getBackgroundPage();
|
||||
|
||||
|
||||
|
||||
readUrl();
|
||||
//on addon click load extension page
|
||||
//
|
||||
function Setup(data)
|
||||
{
|
||||
browser.browserAction.onClicked.addListener(() => {
|
||||
let promise = browser.tabs.create({"url": "home.html"});
|
||||
// promise.then((value) => run(value),()=> failure(value));
|
||||
});
|
||||
browser.runtime.onMessage.addListener(()=>run(data));
|
||||
}
|
||||
|
||||
function failure(value)
|
||||
{
|
||||
console.log("tabs.create returned a failure");
|
||||
}
|
||||
|
||||
browser.browserAction.onClicked.addListener(() => {
|
||||
let promise = browser.tabs.create({"url": "home.html"});
|
||||
//promise.then((value) => run(value),()=> failure(value));
|
||||
});
|
||||
function run(data)
|
||||
{
|
||||
let i2=0;
|
||||
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++;
|
||||
}
|
||||
|
||||
function readUrl()
|
||||
{
|
||||
let data;
|
||||
const filePath = "newpipe_subscriptions_202403101004.json";
|
||||
var localURL = browser.extension.getURL(filePath);
|
||||
fetch(localURL).then((res) => {
|
||||
if(!res.ok){
|
||||
throw new Error
|
||||
(`res error`);
|
||||
}
|
||||
return res.json();
|
||||
})
|
||||
.then((data) => {
|
||||
for(let i=0;i<i;i++) //i in data.subscriptions)
|
||||
{
|
||||
let open=null;
|
||||
console.log(data.subscriptions[i].url);
|
||||
try{
|
||||
open = alert(data.subscriptions[i].url,"_blank");
|
||||
}
|
||||
catch(e) {InsertError(e.description);}
|
||||
}
|
||||
console.log(data);
|
||||
Setup(data);
|
||||
})
|
||||
.catch((error)=> console.error("couldnt fetch data",error));
|
||||
|
||||
|
||||
}
|
||||
|
14
home.js
14
home.js
@ -1,9 +1,17 @@
|
||||
window.onload = run;
|
||||
function run()
|
||||
{
|
||||
document.getElementById("id_run").addEventListener("click", function(e){
|
||||
console.log("triggered!!");
|
||||
alert("judihudi");
|
||||
console.log("triggered!!");
|
||||
alert("judihudi");
|
||||
startBackgroundScript();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
window.onload = run;
|
||||
|
||||
|
||||
function startBackgroundScript()
|
||||
{
|
||||
browser.runtime.sendMessage("Button_clicked");
|
||||
console.log("home.js sent button_clicked message...");
|
||||
}
|
||||
|
18
spawn.js
Normal file
18
spawn.js
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
//1.grant host permission
|
||||
//
|
||||
//
|
||||
browser.runtime.onMessage.addListener((message,listener,handle)
|
||||
|
||||
//if(number>0)
|
||||
function handle()
|
||||
{
|
||||
if(message != 0)//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);
|
||||
console.log(url);
|
||||
}
|
Loading…
Reference in New Issue
Block a user