Skip to content

Commit

Permalink
Merge pull request #2386 from raszpl/patch-16
Browse files Browse the repository at this point in the history
fix playerAutopauseWhenSwitchingTabs when minimizing browser
  • Loading branch information
ImprovedTube authored Jun 18, 2024
2 parents 9e3a96c + 9e76934 commit 13178a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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 @@ -42,15 +42,16 @@ ImprovedTube.forcedPlayVideoFromTheBeginning = function () {
AUTOPAUSE WHEN SWITCHING TABS
------------------------------------------------------------------------------*/
ImprovedTube.playerAutopauseWhenSwitchingTabs = function () {
var player = ImprovedTube.elements.player;

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

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

0 comments on commit 13178a9

Please sign in to comment.