Skip to content

Commit

Permalink
Merge branch 'code-charity:master' into feature-2
Browse files Browse the repository at this point in the history
  • Loading branch information
MAZ01001 authored Nov 15, 2023
2 parents 6c63fcd + 40f651d commit 7fc9da1
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Wish or Feature request, with BOUNTY PAYMENT
about: Wish or Feature request, with BOUNTY PAYMENT
title: ''
labels: Bounty!, Feature request, good first issue, help wanted
assignees: ''

---

<!--
(Click PREVIEW to undestand this template)
OPTIONALLY fill the table if each point fits in the same line:
-->

_REASON / PROBLEM_:
<!-- (Does your IDEA / feature request relate to a Problem? Which problem is?
Ex. I'm always frustrated when [...] )-->

_WISH / SOLUTION_:
<!-- (Describe what you'd like
(A clear and concise description of what you want to happen).
Please consider screenshots or sketches if it makes sense)-->

_BOUNTY_: <!-- How much are you willing to donate / pay for this? and by what method? -->

_ALTERNATIVES_:
<!-- (Describe what you've considered:
Alternative solutions or features, you'd consider as equal or inferior). -->

_RELEVANCE / SCOPE_:
<!-- (Would this be good by for everybody by default? (hypothetically).
Estimate how many percent of our users (or all youtube users) should/would use your idea? ) -->

_"SIDE EFFECTS"_:
<!-- (Is there any conflict with any other feature?
Who might NOT want this?(How many percent of users could be bothered by it even filling space in our menu?)-->

_CONTEXT_: <!-- any other context. -->
//
Thank you!

SHORT Table | (Summary)
------------ | -------------
*Problem* |
*Solution* | <!-- TYPE HERE, 1 line each) -->
*Alternatives*|
*Scope* |
*Side effects*|
*Context* |
6 changes: 3 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
});


/*------ search results in new tab --------- */
/*------ search results in new tab ---------
chrome.storage.local.get('open_new_tab', function (result)
{if (result.open_new_tab === true){
Expand All @@ -274,8 +274,8 @@ chrome.runtime.onMessage.addListener(function (request) {
}
});
}});

}}); */
/*--------------------------------------------------------------
# UNINSTALL URL
--------------------------------------------------------------*/
Expand Down
3 changes: 1 addition & 2 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ extension.events.on('init', function () {
extension.features.markWatchedVideos();
extension.features.relatedVideos();
extension.features.comments();
if (extension.storage.get("open_new_tab") === true) {extension.features.openNewTab();}

extension.features.openNewTab();
bodyReady();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
html {overflow-x: hidden !important; }
/* Fix to tame Youtube's page-load / make it more calm - the player wont annoyingly slide in from the right anymore */
/* previously also: html[it-transcript='true'] {overflow-x: hidden !important; }*/
@-moz-document url-prefix() { overflow-x: visible !important; } /* REMOVE ME SOON https://github.com/code-charity/youtube/issues/1649 */
/*--------------------------------------------------------------
>>> SIDEBAR
----------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions js&css/extension/www.youtube.com/general/general.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* fix for youtube's player moving in from the right side */
html {overflow-x: hidden !important; }
/* html {overflow-x: hidden !important; }
/* Fix to tame Youtube's page-load / make it more calm - the player wont annoyingly slide in from the right anymore */
/* previously also: html[it-transcript='true'] {overflow-x: hidden !important; }*/
@-moz-document url-prefix() { overflow-x: visible !important; } /* REMOVE ME SOON https://github.com/code-charity/youtube/issues/1649 */
/*--------------------------------------------------------------
>>> GENERAL:
----------------------------------------------------------------
Expand Down
48 changes: 33 additions & 15 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,27 +563,45 @@ extension.features.openNewTab = function (){
const searchButton = document.querySelector("button#search-icon-legacy");
const inputField = document.querySelector("input#search");

searchButton.addEventListener("click", (event) => {

performSearchNewTab(event);

searchButton.addEventListener("mousedown", (event) => {
performSearchNewTab(inputField.value);
});
inputField.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
performSearchNewTab(event);
performSearchNewTab(inputField.value);
}
});

function performSearchNewTab(e) {
e.stopImmediatePropagation();

const newTabURL = `https://www.youtube.com/results?search_query=${encodeURIComponent(
inputField.value
)}`;
chrome.runtime.sendMessage({ action: "createNewTab", url: newTabURL });

inputField.value = "";
inputField.focus();

let searchedAlready = false;
inputField.addEventListener("focus", function () {
searchedAlready = false;
const observer = new MutationObserver(applySuggestionListeners);
const container = document.querySelector("div[style*='position: fixed'] ul[role='listbox']");
if (container) observer.observe(container, { attributes: true, childList: true, subtree: true });
});

inputField.addEventListener("input", () => searchedAlready = false);

function applySuggestionListeners() {
const suggestionContainers = document.querySelectorAll("div[class^='sbqs'], div[class^='sbpqs']");
suggestionContainers.forEach((suggestionsContainer) => {
suggestionsContainer.addEventListener("mousedown", (event) => {
const suggestionListItem = event.target.closest("li[role='presentation']");
if (suggestionListItem && !searchedAlready) {
const query = suggestionListItem.querySelector("b").textContent
performSearchNewTab(inputField.value + query);
searchedAlready = true;
}
});
});
}

function performSearchNewTab(query) {
inputField.value = "";
inputField.focus();
const newTabURL = `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`;
window.open(newTabURL, '_blank');
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ ImprovedTube.ytElementsHandler = function (node) {
}
else if (name === 'YTD-TOGGLE-BUTTON-RENDERER' || name === 'YTD-PLAYLIST-LOOP-BUTTON-RENDERER') {
if (
node.parentComponent &&
node.parentComponent.nodeName === 'YTD-MENU-RENDERER' &&
node.parentComponent.parentComponent &&
node.parentComponent.parentComponent.nodeName === 'YTD-PLAYLIST-PANEL-RENDERER'
node.closest("YTD-MENU-RENDERER") &&
node.closest("YTD-PLAYLIST-PANEL-RENDERER")
) {
var index = Array.prototype.indexOf.call(node.parentNode.children, node);

Expand Down Expand Up @@ -418,7 +416,8 @@ ImprovedTube.playerOnEnded = function (event) {

ImprovedTube.messages.send({
action: 'analyzer',
name: ImprovedTube.elements.yt_channel_name.__data.tooltipText,
//adding "?" (not a fix)
name: ImprovedTube.elements.yt_channel_name?.__data.tooltipText,
time: ImprovedTube.played_time
});

Expand Down
49 changes: 25 additions & 24 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ ImprovedTube.playerPlaybackSpeed = function () {

let title = document.getElementsByTagName('meta')?.title?.content || false;
let keywords = document.getElementsByTagName('meta')?.keywords?.content || false;
var musicIdentifiers = /(official|music|lyrics)[ -]video|(cover|studio|radio|album|alternate)[- ]version|theme song|soundtrack|unplugged|\bmedley\b|\blo-fi\b|\blofi\b|a(lla)? cappella|feat\.|(piano|guitar|jazz|ukulele|violin|reggae)[- ](version|cover)|karaok|backing[- ]track|instrumental|(sing|play)[- ]?along|卡拉OK|卡拉OK|الكاريوكي|караоке|カラオケ|노래방|bootleg|mashup|Radio edit|Guest (vocals|musician)|(title|opening|closing|bonus|hidden)[ -]track|live acoustic|interlude|featuring|recorded (at|live)/i;
var musicRegexMatch = musicIdentifiers.test(title);
if (!musicRegexMatch) { musicRegexMatch = /lyrics|\bremix|\bAMV ?[^a-z0-9]|[^a-z0-9] ?AMV\b|\bfull song\b|\bsong:|\bsong[\!$]|^song\b|( - .*\bSong\b|\bSong\b.* - )|cover ?[^a-z0-9]|[^a-z0-9] ?cover|\bconcert\b/i.test(title);
if (!musicRegexMatch) { musicRegexMatch = musicIdentifiers.test(keywords);
if (!musicRegexMatch) { musicRegexMatch = /, (lyrics|remix|song|music|AMV),|\bfull song\b/i.test(keywords);
}
}
}
let notMusicRegexMatch = /\bdo[ck]u|interv[iyj]|back[- ]?stage|インタビュー|entrevista|面试|面試|회견|wawancara|مقابلة|интервью|entretien|기록한 것|记录|記錄|ドキュメンタリ|وثائقي|документальный/i.test(title + " " + keywords); // (Tags/keywords shouldnt lie & very few songs titles might have these words)
var musicIdentifiers = /(official|music|lyrics)[ -]video|(cover|studio|radio|album|alternate)[- ]version|soundtrack|unplugged|\bmedley\b|\blo-fi\b|\blofi\b|a(lla)? cappella|feat\.|(piano|guitar|jazz|ukulele|violin|reggae)[- ](version|cover)|karaok|backing[- ]track|instrumental|(sing|play)[- ]?along|卡拉OK|卡拉OK|الكاريوكي|караоке|カラオケ|노래방|bootleg|mashup|Radio edit|Guest (vocals|musician)|(title|opening|closing|bonus|hidden)[ -]track|live acoustic|interlude|featuring|recorded (at|live)/i;
var musicIdentifiersTitleOnly = /lyrics|theme song|\bremix|\bAMV ?[^a-z0-9]|[^a-z0-9] ?AMV\b|\bfull song\b|\bsong:|\bsong[\!$]|^song\b|( - .*\bSong\b|\bSong\b.* - )|cover ?[^a-z0-9]|[^a-z0-9] ?cover|\bconcert\b/i;
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 musicIdentifiersTags = new RegExp(musicIdentifiersTagsOnly.source + musicIdentifiers.source, "i");
var keywordsAmount = 1 + ((keywords || '').match(/,/) || []).length;
if ( ((keywords || '').match(musicIdentifiersTags) || []).length / keywordsAmount > 0.08) {
musicRegexMatch = true}
}
let notMusicRegexMatch = /\bdo[ck]u|interv[iyj]|back[- ]?stage|インタビュー|entrevista|面试|面試|회견|wawancara|مقابلة|интервью|entretien|기록한 것|记录|記錄|ドキュメンタリ|وثائقي|документальный/i.test(title + " " + keywords);
// (Tags/keywords shouldnt lie & very few songs titles might have these words)
var duration = document.querySelector('meta[itemprop=duration]')?.content || false; // Example: PT1H20M30S
if(!duration) { itemprops = document.getElementsByTagName('meta');
for (var i = 0; i < itemprops.length; i++) {
Expand All @@ -99,13 +103,12 @@ ImprovedTube.playerPlaybackSpeed = function () {
function parseDuration(duration) { const [_, h = 0, m = 0, s = 0] = duration.match(/PT(?:(\d+)?H)?(?:(\d+)?M)?(\d+)?S?/).map(part => parseInt(part) || 0);
return h * 3600 + m * 60 + s; }
var durationInSeconds = parseDuration(duration);
function testSongDuration(s) {
function testSongDuration(s, ytMusic) {
if (135 <= s && s <= 260) {return 'veryCommon';}
if (105 <= s && s <= 420) {return 'common';}
if (420 <= s && s <= 720) {return 'long';}
if (45 <= s && s <= 105) {return 'short';}
let musicSectionLength = document.querySelector('div#items[class*="music-section"]')?.children?.length;
if (musicSectionLength && (85 <= s / musicSectionLength && s / musicSectionLength<= 355)) {return 'multiple';}
if (ytMusic && ytMusic > 1 && (85 <= s / ytMusic && s / ytMusic <= 355)) {return 'multiple';}
}
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 @@ -114,28 +117,26 @@ ImprovedTube.playerPlaybackSpeed = function () {
// check if the video is PROBABLY MUSIC:
if ( ( category === 'Music' && (!notMusicRegexMatch || songDurationType === 'veryCommon'))
|| ( musicRegexMatch && !notMusicRegexMatch && typeof songDurationType !== 'undefined'
|| (/album|Álbum|专辑|專輯|एलबम|البوم|アルバム|альбом|앨범|mixtape|concert|\b(live|cd|vinyl|lp|ep)\b/i.test(title + " " + keywords)
|| (/album|Álbum|专辑|專輯|एलबम|البوم|アルバム|альбом|앨범|mixtape|concert|playlist|\b(live|cd|vinyl|lp|ep|compilation|collection|symphony|suite|medley)\b/i.test(title + " " + keywords)
&& 1150 <= durationInSeconds && durationInSeconds <= 5000) )
|| ( category === 'Music' && musicRegexMatch && typeof songDurationType !== 'undefined'
|| (/album|Álbum|专辑|專輯|एलबम|البوم|アルバム|альбом|앨범|mixtape|concert|\b(live|cd|vinyl|lp|ep)\b/i.test(title + " " + keywords)
|| (/album|Álbum|专辑|專輯|एलबम|البوم|アルバム|альбом|앨범|mixtape|concert|playlist|\b(live|cd|vinyl|lp|ep|compilation|collection|symphony|suite|medley)\b/i.test(title + " " + keywords)
&& 1150 <= durationInSeconds && durationInSeconds <= 5000) )
// || location.href.indexOf('music.') !== -1 // (=currently we are only running on www.youtube.com anyways)
) { } //music player.setPlaybackRate(1); video.playbackRate = 1;
else { player.setPlaybackRate(Number(option)); video.playbackRate = Number(option); // #1729 question2
// Now this video might rarely be music
// - however we can make extra-sure after waiting for the video descripion to load... (#1539)
var tries = 0; var intervalMs = 150; if (location.href.indexOf('/watch?') !== -1) {var maxTries = 10;} else {var maxTries = 1;}
var tries = 0; var intervalMs = 150; if (location.href.indexOf('/watch?') !== -1) {var maxTries = 10;} else {var maxTries = 0;}
// ...except when it is an embedded player?

var waitForDescription = setInterval(() => {
if ((++tries >= maxTries) || document.querySelector('div#description')) {
if (document.querySelector('h3#title[class*="music-section"]') // indicates buyable/registered music
&& typeof testSongDuration(parseDuration(document.querySelector('meta[itemprop=duration]')?.content)) !== 'undefined' ) // resonable duration
{player.setPlaybackRate(1); video.playbackRate = 1; } clearInterval(waitForDescription); }
intervalMs *= 1.4;
}, intervalMs);
}
} else { player.setPlaybackRate(Number(option)); video.playbackRate = Number(option);} // #1729 question2
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
{player.setPlaybackRate(1); video.playbackRate = 1; console.log("Youtube shows music below the description"); clearInterval(waitForDescription); }
intervalMs *= 1.0; }}, intervalMs);

}} else { player.setPlaybackRate(Number(option)); video.playbackRate = Number(option);} // #1729 question2
}
};
// hi @raszpl // ImprovedTube.playerForceSpeedOnMusic = function () { ImprovedTube.playerPlaybackSpeed(); };
Expand Down
5 changes: 3 additions & 2 deletions js&css/web-accessible/www.youtube.com/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ ImprovedTube.shortcuts = function () {
});

document.addEventListener('improvedtube-player-loaded', function () {
ImprovedTube.elements.player.parentNode.addEventListener('mouseover', function () {
//Please Fix: November2023: this parentNode doesnt exist on youtube.com/shorts
ImprovedTube.elements.player.parentNode?.addEventListener('mouseover', function () {
mouse.player = true;
mouse.wheel = 0;
}, true);

ImprovedTube.elements.player.parentNode.addEventListener('mouseout', function () {
ImprovedTube.elements.player.parentNode?.addEventListener('mouseout', function () {
mouse.player = false;
mouse.wheel = 0;
}, true);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name" : "ImprovedTube",
"name": "'Improve YouTube!' 🎧 (for YouTube & Videos)",
"description": "__MSG_description_ext__",
"version": "4.401",
"version": "4.408",
"default_locale": "en",
"icons": {
"16": "stuff/icons/16.png",
Expand Down
13 changes: 9 additions & 4 deletions menu/skeleton-parts/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,15 @@ extension.skeleton.main.layers.section.general = {
remove_home_page_shorts: {
component: 'switch',
text: 'removeHomePageShorts'
}
},
search: {
component: 'section',
variant: 'card',
title: 'Youtube\'s Search',
open_new_tab: {
component: "switch",
text: "openNewTab",
},
remove_related_search_results: {
component: 'switch',
Expand Down Expand Up @@ -1320,10 +1329,6 @@ extension.skeleton.main.layers.section.general = {
text: 'confirmationBeforeClosing',
tags: 'random prevent close exit'
},
open_new_tab: {
component: "switch",
text: "openNewTab",
},
}
}
},
Expand Down

0 comments on commit 7fc9da1

Please sign in to comment.