mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-22 11:40:13 +00:00
implement open in TA
This commit is contained in:
parent
1306dbd6fa
commit
f3064f32b1
@ -138,7 +138,9 @@ async function subscribe(url, subscribed) {
|
|||||||
async function videoExists(id) {
|
async function videoExists(id) {
|
||||||
const path = `api/video/${id}/`;
|
const path = `api/video/${id}/`;
|
||||||
let response = await sendGet(path);
|
let response = await sendGet(path);
|
||||||
return Boolean(response.data);
|
if (!response.data) return false;
|
||||||
|
let access = await getAccess();
|
||||||
|
return new URL(`video/${id}/`, access.url).href;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannelCache() {
|
async function getChannelCache() {
|
||||||
|
@ -278,6 +278,7 @@ function buildChannelDownloadButton() {
|
|||||||
channelDownloadButton.setAttribute('data-type', 'video');
|
channelDownloadButton.setAttribute('data-type', 'video');
|
||||||
channelDownloadButton.setAttribute('data-id', videoId);
|
channelDownloadButton.setAttribute('data-id', videoId);
|
||||||
channelDownloadButton.title = `TA download video: ${videoId}`;
|
channelDownloadButton.title = `TA download video: ${videoId}`;
|
||||||
|
checkVideoExists(channelDownloadButton);
|
||||||
} else {
|
} else {
|
||||||
let toDownload = urlObj.pathname.slice(1);
|
let toDownload = urlObj.pathname.slice(1);
|
||||||
channelDownloadButton.setAttribute('data-id', toDownload);
|
channelDownloadButton.setAttribute('data-id', toDownload);
|
||||||
@ -386,9 +387,14 @@ function processTitle(titleContainer) {
|
|||||||
|
|
||||||
function checkVideoExists(taButton) {
|
function checkVideoExists(taButton) {
|
||||||
function handleResponse(message) {
|
function handleResponse(message) {
|
||||||
let buttonSpan = taButton.querySelector('span');
|
let buttonSpan = taButton.querySelector('span') || taButton;
|
||||||
if (message) {
|
if (message !== false) {
|
||||||
buttonSpan.innerHTML = checkmarkIcon;
|
buttonSpan.innerHTML = checkmarkIcon;
|
||||||
|
buttonSpan.title = 'Open in TA';
|
||||||
|
buttonSpan.addEventListener('click', () => {
|
||||||
|
let win = window.open(message, '_blank');
|
||||||
|
win.focus();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
buttonSpan.innerHTML = downloadIcon;
|
buttonSpan.innerHTML = downloadIcon;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user