mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-22 11:40:13 +00:00
add subscribe button with video url
This commit is contained in:
parent
15c00f3c03
commit
91e7345512
@ -115,6 +115,24 @@ async function downloadLink(toDownload) {
|
||||
|
||||
}
|
||||
|
||||
async function subscribeLink(toSubscribe) {
|
||||
|
||||
const path = "api/channel/";
|
||||
let payload = {
|
||||
"data": [
|
||||
{
|
||||
"channel_id": toSubscribe,
|
||||
"channel_subscribed": true,
|
||||
}
|
||||
]
|
||||
}
|
||||
let access = await getAccess();
|
||||
let response = await sendPost(path, access, payload);
|
||||
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
|
||||
// process and return message if needed
|
||||
function handleMessage(request, sender, sendResponse) {
|
||||
@ -132,6 +150,11 @@ function handleMessage(request, sender, sendResponse) {
|
||||
response.then(message => {
|
||||
sendResponse(message)
|
||||
})
|
||||
} else if (request.subscribe) {
|
||||
let response = subscribeLink(request.subscribe.url);
|
||||
response.then(message => {
|
||||
sendResponse(message)
|
||||
})
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -78,8 +78,7 @@ function setStatusIcon(connected) {
|
||||
}
|
||||
|
||||
|
||||
// download link
|
||||
document.getElementById("download").addEventListener("click", function () {
|
||||
function downloadEvent() {
|
||||
|
||||
let button = document.getElementById("downloadButton");
|
||||
let payload = {
|
||||
@ -94,7 +93,7 @@ document.getElementById("download").addEventListener("click", function () {
|
||||
let download = document.getElementById("download");
|
||||
download.innerHTML = ""
|
||||
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(document.createElement("hr"));
|
||||
})
|
||||
@ -107,7 +106,38 @@ document.getElementById("download").addEventListener("click", function () {
|
||||
let sending = browserType.runtime.sendMessage(payload);
|
||||
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
|
||||
@ -135,25 +165,36 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
|
||||
browserType.storage.local.get("youtube", function(result) {
|
||||
if (result.youtube) {
|
||||
downlodButton(result);
|
||||
createButtons(result);
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
function downlodButton(result) {
|
||||
|
||||
function createButtons(result) {
|
||||
|
||||
let download = document.getElementById("download");
|
||||
let title = document.createElement("p");
|
||||
title.innerText = result.youtube.title;
|
||||
|
||||
let button = document.createElement("button");
|
||||
button.innerText = "download";
|
||||
button.id = "downloadButton";
|
||||
button.setAttribute("data-id", result.youtube.url);
|
||||
// dl button
|
||||
let downloadButton = document.createElement("button");
|
||||
downloadButton.innerText = "download";
|
||||
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(button);
|
||||
download.appendChild(downloadButton);
|
||||
download.appendChild(subscribeButton);
|
||||
download.appendChild(document.createElement("hr"));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user