Skip to content

Commit 27b507d

Browse files
committed
fix(queue): mark Twitch videos as playing and able to queue them again
1 parent ed57fcf commit 27b507d

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

content/shared.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ chrome.runtime.sendMessage({ started: true }, {}, (response) => {
77
});
88

99
// Element may not be available right away when the page loads.
10-
window.getElement = (className, callback) => {
11-
const search = () => document.getElementsByClassName(className)[0];
10+
window.getElement = (selector, callback) => {
11+
const search = () => document.querySelector(selector);
1212
let maxAttempts = 10;
1313
let iid = setInterval(() => {
1414
const $el = search();

content/style.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@
1010
overflow: visible !important;
1111
}
1212

13+
/* Make the button bigger on Twitch */
14+
.qa-controls-bottom .veefeed-next-button {
15+
margin-left: 4px;
16+
}
17+
18+
.qa-controls-bottom .veefeed-next-button svg path {
19+
transform: scale(1.35) translate(-5px, -5px)
20+
}
21+
1322
.veefeed-next-button.veefeed-show {
1423
width: 3em !important;
1524
visibility: visible;
1625
transition: width 200ms;
1726
}
1827

19-
/* On YouTube, its own next button will be hidden when veefeed's is shown. */
28+
/* Hide YouTube's own Next Video button when veefeed's is shown. */
2029
.veefeed-next-button + .ytp-next-button {
2130
transition: width 200ms, visibility 200ms step-end;
2231
}

content/twitch.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
/* global chrome, getElement, setNextButton */
22

3-
getElement('player', ($player) => {
4-
// Since Twitch VODs don't hae a proper title at page load on the tab,
5-
// or even after the video load, we get the title ourselves.
3+
// Wait for player to load.
4+
getElement('.player', ($player) => {
5+
// Since Twitch VODs don't have a proper title at page load on the tab,
6+
// or even after the video loads, we get the title ourselves.
67
getElement('title', ($title) => {
78
chrome.runtime.sendMessage({ title: $title.textContent.trim() });
89
});
910

10-
const $scroll = document.querySelector('#main_col .tse-scroll-content');
11+
// Use the slider on the player to know when the video ends.
12+
const $slider = document.querySelector('.js-player-slider');
13+
let valuemax;
1114
const observer = new MutationObserver(() => {
12-
// If the video has ended, not just paused, the player will have its
13-
// `data-ended` attribute be equal to `true`.
14-
if ($player.getAttribute('data-ended') === 'true') {
15+
if (!valuemax || valuemax <= 0) {
16+
valuemax = parseFloat($slider.getAttribute('aria-valuemax'));
17+
}
18+
let valuenow = parseFloat($slider.getAttribute('aria-valuenow'));
19+
if (valuemax && valuenow + 1 > valuemax) {
1520
observer.disconnect();
21+
$player.setAttribute('data-ended', 'true');
22+
const $scroll = document.querySelector('main .simplebar-scroll-content');
23+
const $tip =
24+
document.querySelector('.qa-theatre-mode-button span.player-tip');
1625
chrome.runtime.sendMessage({
1726
ended: true,
18-
scrollTop: $scroll.scrollTop,
27+
scrollTop: $tip.getAttribute('data-tip') === 'Exit Theatre Mode'
28+
? 0 : $scroll.scrollTop,
1929
});
2030
}
2131
});
22-
observer.observe($player, { attributes: true });
32+
observer.observe($slider, { attributes: true });
2333

24-
const $playButton =
25-
document.getElementsByClassName('js-control-playpause-button')[0];
34+
const $playButton = document.querySelector('button.qa-pause-play-button');
2635
setNextButton($playButton, 'player-button');
2736
});

content/youtube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global chrome, getElement, setNextButton */
22

3-
getElement('ytp-play-button', ($playButton) => {
3+
getElement('.ytp-play-button', ($playButton) => {
44
const observer = new MutationObserver(() => {
55
// if the video has ended, the play button will change to a
66
// swirly replay arrow.

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"matches": [
52-
"https://www.twitch.tv/*/v/*"
52+
"https://www.twitch.tv/videos/*"
5353
],
5454
"js": [
5555
"util/time.js",

0 commit comments

Comments
 (0)