Skip to content

Commit

Permalink
fixed issu #1400
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedLebda committed Feb 25, 2023
1 parent 0f0a399 commit c2c4e91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
34 changes: 15 additions & 19 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,21 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (action === "play") {
chrome.tabs.query({}, function (tabs) {
if (tabs.length > prevTabsLength) {
prevTabsLength = tabs.length;
for (var i = 0, l = tabs.length; i < l; i++) {
var tab = tabs[i];
chrome.tabs.sendMessage(tab.id, {
action: "new-tab-opened",
});
}
} else {
prevTabsLength = tabs.length;
}
for (var i = 0, l = tabs.length; i < l; i++) {
var tab = tabs[i];

if (sender.tab.id !== tab.id) {
chrome.tabs.sendMessage(tab.id, {
action: "another-video-started-playing",
});
}
}
prevTabsLength++;
} else if (tabs.length < prevTabsLength){
prevTabsLength--;
}else{
for (var i = 0, l = tabs.length; i < l; i++) {
prevTabsLength = tabs.length;
var tab = tabs[i];

if (sender.tab.id !== tab.id) {
chrome.tabs.sendMessage(tab.id, {
action: "another-video-started-playing",
});
}
}
}
});
} else if (action === 'options-page-connected') {
sendResponse({
Expand Down
11 changes: 3 additions & 8 deletions content-scripts/extension-context/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ document.addEventListener('DOMContentLoaded', function () {

bodyReady();
});
let prevRequestAction = "";

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === 'focus') {
extension.messages.send({
Expand Down Expand Up @@ -112,16 +112,11 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
extension.messages.send({
deleteCookies: true
});
} else if (
request.action === "another-video-started-playing" &&
prevRequestAction === "new-tab-opened"
) {
console.log("Continue playing");
} else if (request.action === "another-video-started-playing") {
} else if (request.action === "another-video-started-playing") {
extension.features.onlyOnePlayerInstancePlaying();
}

prevRequestAction = request.action;

});

document.addEventListener('it-message-from-youtube', function () {
Expand Down
3 changes: 3 additions & 0 deletions content-scripts/website-context/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ document.addEventListener('it-message-from-extension', function () {
}
}
}
if(ImprovedTube.storage.only_one_player_instance_playing === true){
ImprovedTube.storage = {...ImprovedTube.storage, player_autoplay: false, playlist_autoplay: false}
}
});

/*--------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ ImprovedTube.channelVideosCount = function () {
4.2.3.3 DESCRIPTION
------------------------------------------------------------------------------*/

ImprovedTube.description = function () {
ImprovedTube.description = function (el) {
if (this.storage.description === "expanded") {
document.querySelector("#more").click();
}else if(this.storage.description === "normal"){
document.querySelector("#less").click();
el.click();
}
};

Expand Down

0 comments on commit c2c4e91

Please sign in to comment.