From f3064f32b1822f50ebf5f1ccc473d184830b5851 Mon Sep 17 00:00:00 2001 From: Simon Date: Sat, 26 Aug 2023 22:39:37 +0700 Subject: [PATCH] implement open in TA --- extension/background.js | 4 +++- extension/script.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extension/background.js b/extension/background.js index 57b86ed..1f97efc 100644 --- a/extension/background.js +++ b/extension/background.js @@ -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() { diff --git a/extension/script.js b/extension/script.js index 56f1364..797c471 100644 --- a/extension/script.js +++ b/extension/script.js @@ -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; }