Skip to content

Commit

Permalink
Popup Player: no url bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Nov 17, 2023
1 parent 40f651d commit 7fbb43f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
35 changes: 30 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*--------------------------------------------------------------
>>> BACKGROUND
----------------------------------------------------------------
# webRequest.onBeforeRequest
# Locale
# IMPORTING OLD SETTINGS
# Context menu
# Tab focus/blur
# Message listener
Expand All @@ -11,7 +13,6 @@
/*--------------------------------------------------------------
# LOCALE
--------------------------------------------------------------*/

/*---------------------------
# IMPORTING OLD SETTINGS
-----------------------------*/
Expand Down Expand Up @@ -94,7 +95,7 @@ function updateContextMenu(language) {
chrome.contextMenus.create({
id: String(i),
title: text,
contexts: ['action','browser_action']
contexts: ['browser_action'] //manifest3 : 'action'
});
}

Expand Down Expand Up @@ -254,15 +255,39 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
} else if (action === 'options-page-connected') {
sendResponse({
isTab: sender.hasOwnProperty('tab')
});
});
} else if (action === 'tab-connected') {
sendResponse({
hostname: new URL(sender.url).hostname,
tabId: sender.tab.id
});
}
});
} else if (action === 'fixPopup') {
//no URL-bar
chrome.windows.getLastFocused(w => {
chrome.tabs.query({ windowId: w.id, active: true }, ts => {
const t = ts[0];
const data = { type: "popup" };
if (t) { data.tabId = t.id; }
chrome.windows.create(data, pw => { chrome.windows.update(pw.id, { state: w.state
, width: message.playerSize.width,
height: message.playerSize.height});
});
//title
chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) {
if (tabId === t.id && changeInfo.status === 'complete') {
chrome.tabs.executeScript(t.id, {
code: `document.title = "ImprovedTube Popup Player: ${message.title}";`
});
chrome.tabs.onUpdated.removeListener(listener);
}
});
});
});
};
});

// Create the frameless window with no URL


/*------ search results in new tab ---------
chrome.storage.local.get('open_new_tab', function (result)
Expand Down
8 changes: 8 additions & 0 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ document.addEventListener('it-message-from-youtube', function () {
chrome.runtime.sendMessage({
name: 'only-one-player'
});
} else if (message.action === 'popup player') {
chrome.runtime.sendMessage({
action: 'fixPopup',
url: message.url,
playerSize: { width: message.width, height: message.height },
title: message.title
});

} else if (message.action === 'analyzer') {
if (extension.storage.data.analyzer_activation === true) {
var data = message.name,
Expand Down
17 changes: 12 additions & 5 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ImprovedTube.playerPlaybackSpeed = function () {
var musicIdentifiersTitle = new RegExp(musicIdentifiersTitleOnly.source + musicIdentifiers.source, "i");
var musicRegexMatch = musicIdentifiersTitle.test(title);
if (!musicRegexMatch) {
var musicIdentifiersTagsOnly = /, (lyrics|remix|song|music|AMV|theme song|full song),/i;
var musicIdentifiersTagsOnly = /, (lyrics|remix|song|music|AMV|theme song|full song),|\(Musical Genre\)|, jazz|, reggae/i;
var musicIdentifiersTags = new RegExp(musicIdentifiersTagsOnly.source + musicIdentifiers.source, "i");
var keywordsAmount = 1 + ((keywords || '').match(/,/) || []).length;
if ( ((keywords || '').match(musicIdentifiersTags) || []).length / keywordsAmount > 0.08) {
Expand All @@ -108,7 +108,8 @@ ImprovedTube.playerPlaybackSpeed = function () {
if (105 <= s && s <= 420) {return 'common';}
if (420 <= s && s <= 720) {return 'long';}
if (45 <= s && s <= 105) {return 'short';}
if (ytMusic && ytMusic > 1 && (85 <= s / ytMusic && s / ytMusic <= 355)) {return 'multiple';}
if (ytMusic && ytMusic > 1 && (85 <= s / ytMusic && (s / ytMusic <= 375 || ytMusic == 10))) {return 'multiple';}
//does Youtube ever show more than 10 songs below the description?
}
var songDurationType = testSongDuration(durationInSeconds);
console.log("category: " + category + "//title: " + title + "//keywords: " + keywords + "//music word match: " + musicRegexMatch + "// not music word match:" + notMusicRegexMatch + "//duration: " + duration + "//song duration type: " + songDurationType);
Expand All @@ -132,7 +133,7 @@ ImprovedTube.playerPlaybackSpeed = function () {
var waitForDescription = setInterval(() => {
if (++tries >= maxTries) {
if (document.querySelector('#title + #subtitle') // indicates buyable/registered music
&& typeof testSongDuration(parseDuration(document.querySelector('meta[itemprop=duration]')?.content), Number(document.querySelector('#title + #subtitle')?.innerHTML?.match(/^\d+/)[0]) || false) !== 'undefined' ) // resonable duration
&& typeof testSongDuration(parseDuration(document.querySelector('meta[itemprop=duration]')?.content), Number((document.querySelector('#title + #subtitle')?.innerHTML?.match(/^\d+/) || [])[0])) !== 'undefined' ) // resonable duration
{player.setPlaybackRate(1); video.playbackRate = 1; console.log("Youtube shows music below the description"); clearInterval(waitForDescription); }
intervalMs *= 1.0; }}, intervalMs);

Expand Down Expand Up @@ -711,7 +712,7 @@ ImprovedTube.playerFitToWinButton = function () {
POPUP PLAYER
------------------------------------------------------------------------------*/
ImprovedTube.playerPopupButton = function () {
if (this.storage.player_popup_button === true) {
if (this.storage.player_popup_button === true && location.href.indexOf('youtube.com/embed') === -1 ){
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
path = document.createElementNS('http://www.w3.org/2000/svg', 'path');

Expand All @@ -732,8 +733,14 @@ ImprovedTube.playerPopupButton = function () {
let urlPopup = `${location.protocol}//www.youtube.com/embed/${location.search.match(ImprovedTube.regex.video_id)[1]}?start=${parseInt(player.getCurrentTime())}&autoplay=${(ImprovedTube.storage.player_autoplay ?? true) ? '1' : '0'}`;
const listMatch = location.search.match(ImprovedTube.regex.playlist_id);
if (listMatch) urlPopup += `&list=${listMatch[1]}`;

window.open(urlPopup, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${player.offsetWidth},height=${player.offsetHeight}`);
ImprovedTube.messages.send({
action: 'popup player',
url: urlPopup,
width: player.offsetWidth,
height: player.offsetHeight,
title: document.title
});
},
title: 'Popup'
});
Expand Down

0 comments on commit 7fbb43f

Please sign in to comment.