mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-25 13:10:14 +00:00
sendUrl from injected button
This commit is contained in:
parent
2485715818
commit
a0e4a10f1f
@ -101,47 +101,36 @@ async function verifyConnection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// store last youtube link
|
// send youtube link from injected buttons
|
||||||
function setYoutubeLink(data) {
|
async function youtubeLink(youtubeMessage) {
|
||||||
browserType.storage.local.set(data, function() {
|
|
||||||
console.log("Stored history: " + JSON.stringify(data));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let path;
|
||||||
|
let payload;
|
||||||
|
|
||||||
// send download task to server, return response
|
if (youtubeMessage.action === "download") {
|
||||||
async function downloadLink(toDownload) {
|
path = "api/download/";
|
||||||
|
payload = {
|
||||||
const path = "api/download/";
|
|
||||||
let payload = {
|
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"youtube_id": toDownload,
|
"youtube_id": youtubeMessage.url,
|
||||||
"status": "pending",
|
"status": "pending",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
let response = await sendData(path, payload, "POST")
|
} else if (youtubeMessage.action === "subscribe") {
|
||||||
|
path = "api/channel/";
|
||||||
return response
|
payload = {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async function subscribeLink(toSubscribe) {
|
|
||||||
|
|
||||||
const path = "api/channel/";
|
|
||||||
let payload = {
|
|
||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"channel_id": toSubscribe,
|
"channel_id": youtubeMessage.url,
|
||||||
"channel_subscribed": true,
|
"channel_subscribed": true,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let response = await sendData(path, payload, "POST");
|
let response = await sendData(path, payload, "POST");
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -210,14 +199,7 @@ function handleMessage(request, sender, sendResponse) {
|
|||||||
sendResponse(message);
|
sendResponse(message);
|
||||||
})
|
})
|
||||||
} else if (request.youtube) {
|
} else if (request.youtube) {
|
||||||
setYoutubeLink(request)
|
let response = youtubeLink(request.youtube);
|
||||||
} else if (request.download) {
|
|
||||||
let response = downloadLink(request.download.url);
|
|
||||||
response.then(message => {
|
|
||||||
sendResponse(message)
|
|
||||||
})
|
|
||||||
} else if (request.subscribe) {
|
|
||||||
let response = subscribeLink(request.subscribe.url);
|
|
||||||
response.then(message => {
|
response.then(message => {
|
||||||
sendResponse(message)
|
sendResponse(message)
|
||||||
})
|
})
|
||||||
|
@ -126,7 +126,8 @@ function buildSubLink(channelContainer) {
|
|||||||
subLink.innerText = "Subscribe";
|
subLink.innerText = "Subscribe";
|
||||||
subLink.addEventListener('click', e => {
|
subLink.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log("subscribe to: " + currentLocation)
|
console.log("subscribe to: " + currentLocation);
|
||||||
|
sendUrl(currentLocation, "subscribe");
|
||||||
});
|
});
|
||||||
subLink.addEventListener("mouseover", e => {
|
subLink.addEventListener("mouseover", e => {
|
||||||
let subText
|
let subText
|
||||||
@ -161,6 +162,7 @@ function buildDlLink(channelContainer) {
|
|||||||
dlLink.addEventListener('click', e => {
|
dlLink.addEventListener('click', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log("download: " + currentLocation)
|
console.log("download: " + currentLocation)
|
||||||
|
sendUrl(currentLocation, "download");
|
||||||
});
|
});
|
||||||
dlLink.addEventListener("mouseover", e => {
|
dlLink.addEventListener("mouseover", e => {
|
||||||
let channelName = channelContainer.querySelector("#text").textContent;
|
let channelName = channelContainer.querySelector("#text").textContent;
|
||||||
@ -217,6 +219,7 @@ function buildVideoButton(thumbContainer) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let videoLink = thumbContainer.href;
|
let videoLink = thumbContainer.href;
|
||||||
console.log("download: " + videoLink);
|
console.log("download: " + videoLink);
|
||||||
|
sendUrl(videoLink, "download");
|
||||||
});
|
});
|
||||||
dlButton.addEventListener('mouseover', e => {
|
dlButton.addEventListener('mouseover', e => {
|
||||||
Object.assign(dlButton.style, {
|
Object.assign(dlButton.style, {
|
||||||
@ -286,26 +289,18 @@ function ensureTALinks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendUrl() {
|
function sendUrl(url, action) {
|
||||||
|
|
||||||
let url = document.URL
|
|
||||||
|
|
||||||
let urlType = detectUrlType(url);
|
|
||||||
if (urlType == false) {
|
|
||||||
console.log("not relevant")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let payload = {
|
let payload = {
|
||||||
"youtube": {
|
"youtube": {
|
||||||
"url": url,
|
"url": url,
|
||||||
"title": document.title,
|
"action": action,
|
||||||
"type": urlType,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("youtube link: " + JSON.stringify(payload));
|
console.log("youtube link: " + JSON.stringify(payload));
|
||||||
browserType.runtime.sendMessage(payload, function(response) {
|
browserType.runtime.sendMessage(payload, function(response) {
|
||||||
console.log(response.farewell);
|
console.log("sendUrl response: " + JSON.stringify(response))
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user