Skip to content
New issue

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

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

Already on GitHub? # to your account

fix playerAutopauseWhenSwitchingTabs when minimizing browser #2386

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ chrome.windows.onFocusChanged.addListener(function (wId) {
windowId = wId;
//console.log('onFocusChanged', windowId, tabPrev, tab);
tabPrune(function () {
if (windowId != tab.windowId && tab.tabId && tabConnected[tab.tabId]) {
if (windowId != tab.windowId && tab.tabId && !tab.blur && tabConnected[tab.tabId]) {
tab.blur = true;
chrome.tabs.sendMessage(tab.tabId, {action: 'blur'});
//console.log('blur', tab.tabId, windowId);
} else if (windowId && tab.tabId && tabConnected[tab.tabId]) {
} else if (windowId == tab.windowId && tab.tabId && tab.blur && tabConnected[tab.tabId]) {
tab.blur = false;
chrome.tabs.sendMessage(tab.tabId, {action: 'focus'});
//console.log('focus', tab.tabId, windowId);
}
Expand Down
15 changes: 8 additions & 7 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ ImprovedTube.forcedPlayVideoFromTheBeginning = function () {
AUTOPAUSE WHEN SWITCHING TABS
------------------------------------------------------------------------------*/
ImprovedTube.playerAutopauseWhenSwitchingTabs = function () {
var player = ImprovedTube.elements.player;
const player = this.elements.player;

if (this.storage.player_autopause_when_switching_tabs === true && player) {
if (this.focus === false) {
this.played_before_blur = player.getPlayerState() === 1;

player.pauseVideo();
} else if (this.focus === true && this.played_before_blur === true) {
if (this.storage.player_autopause_when_switching_tabs && player) {
if (this.focus && this.played_before_blur && this.elements.video.paused) {
player.playVideo();
} else {
this.played_before_blur = !this.elements.video.paused;
if (!this.elements.video.paused) {
player.pauseVideo();
}
}
}
};
Expand Down
Loading