mirror of
https://github.com/tubearchivist/browser-extension.git
synced 2024-11-22 11:40:13 +00:00
implement extract video id on hover
This commit is contained in:
parent
4f54e1f863
commit
f8d69f5883
@ -326,12 +326,9 @@ function getTitleContainers() {
|
|||||||
return elements;
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildVideoButton(titleContainer) {
|
function getVideoId(titleContainer) {
|
||||||
let href = getNearestLink(titleContainer);
|
let href = getNearestLink(titleContainer);
|
||||||
if (!href) return;
|
if (!href) return;
|
||||||
const dlButton = document.createElement('a');
|
|
||||||
dlButton.classList.add('ta-button');
|
|
||||||
dlButton.href = '#';
|
|
||||||
|
|
||||||
let videoId;
|
let videoId;
|
||||||
if (href.startsWith('/watch?v')) {
|
if (href.startsWith('/watch?v')) {
|
||||||
@ -340,11 +337,16 @@ function buildVideoButton(titleContainer) {
|
|||||||
} else if (href.startsWith('/shorts/')) {
|
} else if (href.startsWith('/shorts/')) {
|
||||||
videoId = href.split('/')[2];
|
videoId = href.split('/')[2];
|
||||||
}
|
}
|
||||||
|
return videoId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildVideoButton(titleContainer) {
|
||||||
|
let videoId = getVideoId(titleContainer);
|
||||||
if (!videoId) return;
|
if (!videoId) return;
|
||||||
|
|
||||||
dlButton.setAttribute('data-id', videoId);
|
const dlButton = document.createElement('a');
|
||||||
dlButton.setAttribute('data-type', 'video');
|
dlButton.classList.add('ta-button');
|
||||||
dlButton.title = `TA download video: ${titleContainer.innerText} [${videoId}]`;
|
dlButton.href = '#';
|
||||||
|
|
||||||
Object.assign(dlButton.style, {
|
Object.assign(dlButton.style, {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@ -435,7 +437,12 @@ function checkVideoExists(taButton) {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
let videoId = taButton.dataset.id;
|
if (!taButton.parentElement) return;
|
||||||
|
let videoId = getVideoId(taButton.parentElement);
|
||||||
|
taButton.setAttribute('data-id', videoId);
|
||||||
|
taButton.setAttribute('data-type', 'video');
|
||||||
|
taButton.title = `TA download video: ${taButton.parentElement.innerText} [${videoId}]`;
|
||||||
|
|
||||||
let message = { type: 'videoExists', videoId };
|
let message = { type: 'videoExists', videoId };
|
||||||
let sending = sendMessage(message);
|
let sending = sendMessage(message);
|
||||||
sending.then(handleResponse, handleError);
|
sending.then(handleResponse, handleError);
|
||||||
|
Loading…
Reference in New Issue
Block a user