|
|
@ -78,8 +78,7 @@ function setStatusIcon(connected) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// download link
|
|
|
|
function downloadEvent() {
|
|
|
|
document.getElementById("download").addEventListener("click", function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let button = document.getElementById("downloadButton");
|
|
|
|
let button = document.getElementById("downloadButton");
|
|
|
|
let payload = {
|
|
|
|
let payload = {
|
|
|
@ -94,7 +93,7 @@ document.getElementById("download").addEventListener("click", function () {
|
|
|
|
let download = document.getElementById("download");
|
|
|
|
let download = document.getElementById("download");
|
|
|
|
download.innerHTML = ""
|
|
|
|
download.innerHTML = ""
|
|
|
|
let message = document.createElement("p");
|
|
|
|
let message = document.createElement("p");
|
|
|
|
message.innerText = "Link sent to Tube Archivist"
|
|
|
|
message.innerText = "Download link sent to Tube Archivist"
|
|
|
|
download.appendChild(message)
|
|
|
|
download.appendChild(message)
|
|
|
|
download.appendChild(document.createElement("hr"));
|
|
|
|
download.appendChild(document.createElement("hr"));
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -107,7 +106,38 @@ document.getElementById("download").addEventListener("click", function () {
|
|
|
|
let sending = browserType.runtime.sendMessage(payload);
|
|
|
|
let sending = browserType.runtime.sendMessage(payload);
|
|
|
|
sending.then(handleResponse, handleError)
|
|
|
|
sending.then(handleResponse, handleError)
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function subscribeEvent() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let button = document.getElementById("subscribeButton");
|
|
|
|
|
|
|
|
let payload = {
|
|
|
|
|
|
|
|
"subscribe": {
|
|
|
|
|
|
|
|
"url": button.getAttribute("data-id")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleResponse(message) {
|
|
|
|
|
|
|
|
console.log("popup.js response: " + JSON.stringify(message));
|
|
|
|
|
|
|
|
browserType.storage.local.remove("youtube").then(response => {
|
|
|
|
|
|
|
|
let download = document.getElementById("download");
|
|
|
|
|
|
|
|
download.innerHTML = ""
|
|
|
|
|
|
|
|
let message = document.createElement("p");
|
|
|
|
|
|
|
|
message.innerText = "Subscribe link sent to Tube Archivist"
|
|
|
|
|
|
|
|
download.appendChild(message)
|
|
|
|
|
|
|
|
download.appendChild(document.createElement("hr"));
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleError(error) {
|
|
|
|
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let sending = browserType.runtime.sendMessage(payload);
|
|
|
|
|
|
|
|
sending.then(handleResponse, handleError)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fill in form
|
|
|
|
// fill in form
|
|
|
@ -135,25 +165,36 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
|
|
|
|
|
|
|
|
|
browserType.storage.local.get("youtube", function(result) {
|
|
|
|
browserType.storage.local.get("youtube", function(result) {
|
|
|
|
if (result.youtube) {
|
|
|
|
if (result.youtube) {
|
|
|
|
downlodButton(result);
|
|
|
|
createButtons(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
function downlodButton(result) {
|
|
|
|
|
|
|
|
|
|
|
|
function createButtons(result) {
|
|
|
|
|
|
|
|
|
|
|
|
let download = document.getElementById("download");
|
|
|
|
let download = document.getElementById("download");
|
|
|
|
let title = document.createElement("p");
|
|
|
|
let title = document.createElement("p");
|
|
|
|
title.innerText = result.youtube.title;
|
|
|
|
title.innerText = result.youtube.title;
|
|
|
|
|
|
|
|
|
|
|
|
let button = document.createElement("button");
|
|
|
|
// dl button
|
|
|
|
button.innerText = "download";
|
|
|
|
let downloadButton = document.createElement("button");
|
|
|
|
button.id = "downloadButton";
|
|
|
|
downloadButton.innerText = "download";
|
|
|
|
button.setAttribute("data-id", result.youtube.url);
|
|
|
|
downloadButton.id = "downloadButton";
|
|
|
|
|
|
|
|
downloadButton.setAttribute("data-id", result.youtube.url);
|
|
|
|
|
|
|
|
downloadButton.addEventListener("click", function(){downloadEvent()}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// subscribe button
|
|
|
|
|
|
|
|
let subscribeButton = document.createElement("button");
|
|
|
|
|
|
|
|
subscribeButton.innerText = "subscribe";
|
|
|
|
|
|
|
|
subscribeButton.id = "subscribeButton";
|
|
|
|
|
|
|
|
subscribeButton.setAttribute("data-id", result.youtube.url);
|
|
|
|
|
|
|
|
subscribeButton.addEventListener("click", function(){subscribeEvent()}, false);
|
|
|
|
|
|
|
|
|
|
|
|
download.appendChild(title);
|
|
|
|
download.appendChild(title);
|
|
|
|
download.appendChild(button);
|
|
|
|
download.appendChild(downloadButton);
|
|
|
|
|
|
|
|
download.appendChild(subscribeButton);
|
|
|
|
download.appendChild(document.createElement("hr"));
|
|
|
|
download.appendChild(document.createElement("hr"));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|