Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix button not being injected on certain videos #35

Merged
merged 1 commit into from
Feb 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const newYouTube = {
},

registerListeners() {
document.addEventListener('yt-visibility-refresh', newYouTube.inject); // Inject the button on info panel render.
document.addEventListener('yt-register-action', newYouTube.inject); // Inject the button on comments render.
document.addEventListener('yt-page-data-updated', newYouTube.injectCommentsCount); // Asynchronously get comments count when navigated to video page
window.addEventListener('focus', newYouTube._waitCommentsCount); // When the YouTube tab is in the background state and navigate to the next movie by auto-play, the node of comments is not updated. So set this event when the user returns to Youtube tab.
},
Expand All @@ -159,23 +159,23 @@ const newYouTube = {
newYouTube._addClass();
newYouTube._addButton();

document.removeEventListener('yt-visibility-refresh', newYouTube.inject);
document.removeEventListener('yt-register-action', newYouTube.inject);
},

_ready(e) {
return (
newYouTube.isVideo() &&
!newYouTube.isLiveVideo() &&
(newYouTube._isInfoPanelRendered(e) ||
(newYouTube._isCommentsRendered(e) ||
newYouTube._isPageNavigated(e))
);
},

_isInfoPanelRendered(e) {
_isCommentsRendered(e) {
return (
typeof e !== 'undefined' &&
e.type === 'yt-visibility-refresh' &&
e.target.tagName === 'YTD-ITEM-SECTION-RENDERER' // this mean: rendered childNode of comments'DOM(<ytd-comments>)
e.type === 'yt-register-action' &&
e.target.tagName === 'YTD-COMMENTS'
);
},

Expand Down