Skip to content

Commit

Permalink
#1844 (3&4) #1872
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Dec 13, 2023
1 parent aed2199 commit 0c0e31f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 56 deletions.
41 changes: 22 additions & 19 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,27 +260,30 @@ try{ sendResponse({
windowId: w.id,
active: true
}, ts => {
tID = ts[0]?.id,
data = { type: 'popup' };
if (tID) data.tabId = tID;
chrome.windows.create(data, pw => {
chrome.windows.update(pw.id, {
state: w.state,
width: message.width,
height: message.height
});
});
//append to title
chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) {
if (tabId === tID && changeInfo.status === 'complete' && !message.title.startsWith("undefined")) {
chrome.tabs.executeScript(tID, {
code: `document.title = "${message.title} - ImprovedTube";`
});
chrome.tabs.onUpdated.removeListener(listener);
}
});
const tID = ts[0]?.id,
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: -3,
top: 3
};

if (tID) {data.tabId = tID;}
chrome.windows.create(data, pw => { });

//append to title

chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) {
if (tabId === tID && changeInfo.status === 'complete' && !message.title.startsWith("undefined")){
chrome.tabs.onUpdated.removeListener(listener);
chrome.tabs.executeScript(tID, {code: `document.title = "${message.title} - ImprovedTube";`});
}});

});
});


};
});

Expand Down
38 changes: 19 additions & 19 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,30 @@ path.setAttribute('d', 'M19 7h-8v6h8V7zm2-4H3C2 3 1 4 1 5v14c0 1 1 2 2 2h18c1 0
svg.appendChild(path);
target.itPopupWindowButton.appendChild(svg);
target.appendChild(target.itPopupWindowButton);
try { target.itPopupWindowButton.dataset.id = target.href.match(/(?:[?&]v=|embed\/|shorts\/)([^&?]{11})/)[1] } catch(error) { console.log(error)}
shorts = /short/.test(target.href);
vertical = false; let width, height;
if ( window.innerWidth / window.innerHeight < 1 ) { vertical = true }
if ( !vertical && shorts ){ height = window.innerHeight * 0.7}
if ( vertical && !shorts ){ width = window.innerWidth * 0.65 }
if ( !vertical && !shorts ){ height = window.innerHeight *0.47 }
if ( vertical && shorts ){ width = window.innerWidth *0.38 }
if ( !vertical ) { width = height * 0.5625;} else { height = width * 0.5625}
console.log(shorts + "v:" + vertical + "w:" + width + "h:" + height);

target.itPopupWindowButton.addEventListener('click', function (event) {
event.preventDefault();
event.stopPropagation();

window.open('https://www.youtube.com/embed/' + this.dataset.id + '?autoplay=' + (extension.storage.get('player_autoplay') == false ? '0' : '1'), '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width},height=${height}`);
chrome.runtime.sendMessage({
event.stopPropagation();
try { this.parentElement.itPopupWindowButton.dataset.id = this.parentElement.href.match(/(?:[?&]v=|embed\/|shorts\/)([^&?]{11})/)[1] } catch(error) { console.log(error)};
ytPlayer = document.querySelector("#movie_player");
if (ytPlayer){width = ytPlayer.offsetWidth * 0.65; height = ytPlayer.offsetHeight * 0.65}
else { width = innerWidth * 0.4; height = innerHeight * 0.4; }
if (!ytPlayer) {
let shorts = /short/.test(this.parentElement.href);
if ( width / height < 1 ) { let vertical = true } else { let vertical = false }
if ( !vertical && shorts ){ width = height * 0.6}
if ( vertical && !shorts ){ height = width * 0.6}
}

window.open('https://www.youtube.com/embed/' + this.dataset.id + '?autoplay=' + (extension.storage.get('player_autoplay') == false ? '0' : '1'), '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`);
chrome.runtime.sendMessage({
action: 'fixPopup',
width: width,
height: height,
title: target.closest('*[id="video-title"]')?.textContent + " - Youtube"
})
});
}

title: this.parentElement.closest('*[id="video-title"]')?.textContent + " - Youtube"
})
});
}
detected = true;
}
target = target.parentNode;
Expand Down
6 changes: 3 additions & 3 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ ImprovedTube.ytElementsHandler = function (node) {
var node = mutation.addedNodes[j];

if (node instanceof Element
&& node.querySelector('ytp-ad-player-overlay, .ytp-ad-text, .ytp-ad-overlay-close-container, ytd-button-renderer#dismiss-button, *[id^="ad-text"], .ytp-ad-skip-button.ytp-button') !== null
){ImprovedTube.playerAds(node);}
&& node.querySelector('ytp-ad-player-overlay, .ytp-ad-text, .ytp-ad-overlay-close-container, ytd-button-renderer#dismiss-button, *[id^="ad-text"], *[id^="skip-button"], .ytp-ad-skip-button.ytp-button, .ytp-ad-skip-button-modern.ytp-button') !== null
){ImprovedTube.playerAds(node);}
}
}
if (mutation.type === 'attributes' && mutation.attributeName === 'id' && mutation.target.querySelector('*[id^="ad-text"]') )
if (mutation.type === 'attributes' && mutation.attributeName === 'id' && mutation.target.querySelector('*[id^="ad-text"], *[id^="skip-button"], .ytp-ad-skip-button-modern.ytp-button',) )
{ImprovedTube.playerAds(node);}
}
}).observe(node, {
Expand Down
9 changes: 4 additions & 5 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ ImprovedTube.playerPopupButton = function () {
popup = window.open(
`${location.protocol}//www.youtube.com/embed/${videoID}?start=${parseInt(ytPlayer.getCurrentTime())}&autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}${listMatch?`&list=${listMatch[1]}`:''}`,
'_blank',
`directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${ytPlayer.offsetWidth},height=${ytPlayer.offsetHeight}`
`directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${ytPlayer.offsetWidth / 3},height=${ytPlayer.offsetHeight / 3}`
);
if(popup && listMatch){
//! If the video is not in the playlist or not within the first 200 entries, then it automatically selects the first video in the list.
Expand All @@ -832,10 +832,9 @@ ImprovedTube.playerPopupButton = function () {
}
//~ change focused tab to URL-less popup
ImprovedTube.messages.send({
action: 'fixPopup',

width: ytPlayer.offsetWidth * .8 ,
height: ytPlayer.offsetHeight * .8 ,
action: 'fixPopup',
width: ytPlayer.offsetWidth * 0.75,
height: ytPlayer.offsetHeight * 0.75,
title: document.title
});
},
Expand Down
30 changes: 20 additions & 10 deletions js&css/web-accessible/www.youtube.com/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,18 @@ ImprovedTube.playlistPopupCreateButton = function (playlistID, altButtonStyle, c
button.dataset.list = playlistID;
button.style.opacity = '0.8';
button.addEventListener(
'click',
'click',
(checkVideo ?? false) ? function (event) {
"use strict";
const videoURL = ImprovedTube.elements.player?.getVideoUrl();
let width = ImprovedTube.elements.player.offsetWidth * 0.7 ?? innerWidth * 0.4;
let height = ImprovedTube.elements.player.offsetHeight * 0.7 ?? innerHeight * 0.4;

"use strict";
if (videoURL != null && ImprovedTube.regex.video_id.test(videoURL)) {
ImprovedTube.elements.player.pauseVideo();
const listID = this.dataset.list,
videoID = videoURL.match(ImprovedTube.regex.video_id)[1],
popup = window.open(`${location.protocol}//www.youtube.com/embed/${videoID}?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&start=${videoURL.match(ImprovedTube.regex.video_time)?.[1] ?? '0'}&list=${listID}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${ImprovedTube.elements.player.offsetWidth ?? innerWidth},height=${ImprovedTube.elements.player.offsetHeight ?? innerHeight}`);
popup = window.open(`${location.protocol}//www.youtube.com/embed/${videoID}?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&start=${videoURL.match(ImprovedTube.regex.video_time)?.[1] ?? '0'}&list=${listID}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`);
//! If the video is not in the playlist or not within the first 200 entries, then it automatically selects the first video in the list.
//! But this is okay since this button is mainly for the playlist, not the video (see the video popup button in player.js).
popup.addEventListener('load', function () {
Expand All @@ -176,23 +179,30 @@ ImprovedTube.playlistPopupCreateButton = function (playlistID, altButtonStyle, c
const videoLink = this.document.querySelector('div#player div.ytp-title-text>a[href]');
if (videoLink && videoLink.href.match(ImprovedTube.regex.video_id)[1] !== videoID) this.location.href = `${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&list=${listID}`;
}, {passive: true, once: true});
} else window.open(`${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&list=${this.dataset.list}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${innerWidth},height=${innerHeight}`);
} else window.open(`${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&list=${this.dataset.list}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`);
//~ change focused tab to URL-less popup
ImprovedTube.messages.send({
action: 'fixPopup',
width: ImprovedTube.elements.player?.offsetWidth ?? innerWidth,
height: ImprovedTube.elements.player?.offsetHeight ?? innerHeight,
width: width,
height: height,
title: document.title
});
} : function (event) {
let width = ImprovedTube.elements.player.offsetWidth * 0.7 ?? innerWidth * 0.45;
let height = ImprovedTube.elements.player.offsetHeight * 0.7 ?? innerHeight * 0.45;
if (!ImprovedTube.elements.player) {
shorts = /short/.test(this.parentElement.href);
if ( width / height < 1 ) { vertical = true } else { vertical = false }
if ( !vertical && shorts ){ width = height * 0.6}
if ( vertical && !shorts ){ height = width * 0.6} }
"use strict";
window.open(`${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&list=${this.dataset.list}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${innerWidth},height=${innerHeight}`);
window.open(`${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}&list=${this.dataset.list}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`);
//~ change focused tab to URL-less popup
ImprovedTube.messages.send({
action: 'fixPopup',
width: window.innerWidth/1.3,
height: window.innerHeight/1.3,
title: document.title,
width: width,
height: height,
title: document.title
});
},
true
Expand Down

0 comments on commit 0c0e31f

Please sign in to comment.