implement open in TA

This commit is contained in:
Simon 2023-08-26 22:39:37 +07:00
parent 1306dbd6fa
commit f3064f32b1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 11 additions and 3 deletions

View File

@ -138,7 +138,9 @@ async function subscribe(url, subscribed) {
async function videoExists(id) {
const path = `api/video/${id}/`;
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() {

View File

@ -278,6 +278,7 @@ function buildChannelDownloadButton() {
channelDownloadButton.setAttribute('data-type', 'video');
channelDownloadButton.setAttribute('data-id', videoId);
channelDownloadButton.title = `TA download video: ${videoId}`;
checkVideoExists(channelDownloadButton);
} else {
let toDownload = urlObj.pathname.slice(1);
channelDownloadButton.setAttribute('data-id', toDownload);
@ -386,9 +387,14 @@ function processTitle(titleContainer) {
function checkVideoExists(taButton) {
function handleResponse(message) {
let buttonSpan = taButton.querySelector('span');
if (message) {
let buttonSpan = taButton.querySelector('span') || taButton;
if (message !== false) {
buttonSpan.innerHTML = checkmarkIcon;
buttonSpan.title = 'Open in TA';
buttonSpan.addEventListener('click', () => {
let win = window.open(message, '_blank');
win.focus();
});
} else {
buttonSpan.innerHTML = downloadIcon;
}