Skip to content

Commit

Permalink
fix checkVideoExists, check siblings in getNearestLink
Browse files Browse the repository at this point in the history
  • Loading branch information
bbilly1 committed May 13, 2024
1 parent 9ba90e4 commit 7b40dc4
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions extension/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@ function buildVideoButton(titleContainer) {
}

function getNearestLink(element) {
// Check siblings
let sibling = element;
while (sibling) {
sibling = sibling.previousElementSibling;
if (sibling && sibling.tagName === 'A' && sibling.getAttribute('href') !== '#') {
return sibling.getAttribute('href');
}
}

sibling = element;
while (sibling) {
sibling = sibling.nextElementSibling;
if (sibling && sibling.tagName === 'A' && sibling.getAttribute('href') !== '#') {
return sibling.getAttribute('href');
}
}

// Check parent elements
for (let i = 0; i < 5 && element && element !== document; i++) {
if (element.tagName === 'A' && element.getAttribute('href') !== '#') {
return element.getAttribute('href');
Expand Down Expand Up @@ -453,12 +471,14 @@ function checkVideoExists(taButton) {
console.error(e);
}

let aElem = taButton?.parentElement?.querySelector('a');
let videoId = getVideoId(aElem);;
if (aElem) {
taButton.setAttribute('data-id', videoId);
taButton.setAttribute('data-type', 'video');
taButton.title = `TA download video: ${taButton.parentElement.innerText} [${videoId}]`;
let videoId = taButton.dataset.id;
if (!videoId) {
videoId = getVideoId(taButton);
if (videoId) {
taButton.setAttribute('data-id', videoId);
taButton.setAttribute('data-type', 'video');
taButton.title = `TA download video: ${taButton.parentElement.innerText} [${videoId}]`;
}
}

let message = { type: 'videoExists', videoId };
Expand Down

0 comments on commit 7b40dc4

Please sign in to comment.