browser file added

This commit is contained in:
ccppi 2024-03-20 09:05:14 +01:00
parent 1e0e313113
commit 3d3a276dd5
5 changed files with 33 additions and 44 deletions

View File

@ -1,7 +1,8 @@
let backgroundPage = browser.extension.getBackgroundPage(); let backgroundPage = browser.extension.getBackgroundPage();
let data;
let i=0;
var data;
let i=0;
/*
data = readUrl() data = readUrl()
.then(function(data){ .then(function(data){
browser.browserAction.onClicked.addListener(function(event1){ browser.browserAction.onClicked.addListener(function(event1){
@ -12,8 +13,16 @@ data = readUrl()
}); });
}); });
}); });
*/
browser.browserAction.onClicked.addListener(function(event1){
browser.tabs.create({"url": "home.html"},function(tab){
browser.runtime.onMessage.addListener(function(request,sender,sendResponse){
handleMessages(request,sender,sendResponse,tab);
});
});
});
function handleMessages(message,sender,sendResponse,tab){
function handleMessages(message,sender,sendResponse,tab,data){
if(message === "Button_clicked") if(message === "Button_clicked")
{ {
browser.tabs.executeScript(tab.id,{ browser.tabs.executeScript(tab.id,{
@ -40,6 +49,7 @@ function handleMessages(message,sender,sendResponse,tab,data){
{ {
i++; i++;
console.log("background: received next from spawn.js"); console.log("background: received next from spawn.js");
console.log("URL:",data.subscriptions[i].url);
browser.tabs.update(tab.id,{url : data.subscriptions[i].url}); browser.tabs.update(tab.id,{url : data.subscriptions[i].url});
browser.tabs.executeScript(tab.id,{ browser.tabs.executeScript(tab.id,{
file:"spawn.js" file:"spawn.js"
@ -47,19 +57,22 @@ function handleMessages(message,sender,sendResponse,tab,data){
browser.tabs.sendMessage(tab.id,data.subscriptions[i].url); browser.tabs.sendMessage(tab.id,data.subscriptions[i].url);
} }
else if(message.status == "FileChange")
{
let file = message.file;
const reader = new FileReader();
reader.addEventListener("load",()=>{
data = JSON.parse(reader.result);
console.log(data);
},false);
if(file)
{
reader.readAsText(file);
}
}
} }
function readFile()
{
const fileField = document.querySelector('input[type="file"]');
fileField.addEventListener("change",() =>
{
console.log(fileField.files[0]);
});
var reader = new FileReader();
function readUrl() function readUrl()
{ {

View File

@ -3,8 +3,11 @@
<div id="picker_zone" style="margin:20px ;color:blue"> <div id="picker_zone" style="margin:20px ;color:blue">
<input type="file" accept="*.json" id="input"> <input type="file" accept="*.json" id="input">
</div> </div>
test <p>1. First login into yout youtube account.<br>
<button type="submit" id="id_run" value="run importer" name="b_submit">RUNRUNRUN</button> 2. Select the Newpipe.json file with the subscriptions to import<br>
3. Press Start<br>
4. Wait<br></p>
<button type="submit" id="id_run" value="run importer" name="b_submit">Start Import</button>
<script type="text/javascript" language="javascript" src="home.js"></script> <script type="text/javascript" language="javascript" src="home.js"></script>
</body> </body>
</html> </html>

View File

@ -3,6 +3,7 @@ const fileField = document.querySelector('input[type="file"]');
fileField.addEventListener("change",() => fileField.addEventListener("change",() =>
{ {
console.log(fileField.files[0]); console.log(fileField.files[0]);
browser.runtime.sendMessage({status:"FileChange",file: fileField.files[0]});
}); });
document.getElementById("id_run").addEventListener("click", function(e){ document.getElementById("id_run").addEventListener("click", function(e){

File diff suppressed because one or more lines are too long

27
yt.js
View File

@ -1,27 +0,0 @@
document.body.style.border = "5px solid red";
const filePath = "newpipe_subscriptions_202403101004.json";
var localURL = browser.extension.getURL(filePath);
var w=[];
fetch(localURL)
.then((res) => {
if(!res.ok){
throw new Error
(`res error`);
}
return res.json();
})
.then((data) => {
for(let i=0;i<3;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);}
}
})
.catch((error)=> console.error("couldnt fetch data",error));