Skip to content

Commit

Permalink
Merge pull request #1729 from raszpl/raszpl-patch-1
Browse files Browse the repository at this point in the history
draft
  • Loading branch information
ImprovedTube committed Aug 29, 2023
2 parents 29e1252 + cb7b7d1 commit 7b3020f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
8 changes: 4 additions & 4 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ ImprovedTube.ytElementsHandler = function (node) {
//if(node.getAttribute('name') === 'description') {ImprovedTube.description = node.content;} //duplicate
//if node.getAttribute('name') === 'themeColor') {ImprovedTube.themeColor = node.content;} //might help our darkmode/themes
//Do we need any of these here before the player starts?
if(node.getAttribute('name') === 'keywords') {ImprovedTube.keywords = node.content;}
//if(node.getAttribute('name') === 'keywords') {ImprovedTube.keywords = node.content;}
} else if (node.getAttribute('itemprop')) {
if(node.getAttribute('itemprop') === 'name') {ImprovedTube.title = node.content;}
if(node.getAttribute('itemprop') === 'genre') {ImprovedTube.category = node.content;}
//if(node.getAttribute('itemprop') === 'name') {ImprovedTube.title = node.content;}
//if(node.getAttribute('itemprop') === 'genre') {ImprovedTube.category = node.content;}
//if(node.getAttribute('itemprop') === 'channelId') {ImprovedTube.channelId = node.content;}
//if(node.getAttribute('itemprop') === 'videoId') {ImprovedTube.videoId = node.content;}
//The following infos will enable awesome, smart features. Some of which everyone should use.
Expand Down Expand Up @@ -332,7 +332,7 @@ ImprovedTube.initPlayer = function () {
delete ImprovedTube.elements.player.dataset.defaultQuality;

ImprovedTube.forcedPlayVideoFromTheBeginning();
ImprovedTube.playerPlaybackSpeed(false);
ImprovedTube.playerPlaybackSpeed();
ImprovedTube.subtitles();
ImprovedTube.subtitlesLanguage();
ImprovedTube.subtitlesFontFamily();
Expand Down
52 changes: 31 additions & 21 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ImprovedTube.playerAutoPip = function () {
/*------------------------------------------------------------------------------
FORCED PLAYBACK SPEED
------------------------------------------------------------------------------*/
ImprovedTube.playerPlaybackSpeed = function (change) {
ImprovedTube.playerPlaybackSpeed = function () {
var player = this.elements.player,
video = player.querySelector('video'),
option = this.storage.player_playback_speed,
Expand All @@ -76,27 +76,37 @@ ImprovedTube.playerPlaybackSpeed = function (change) {
option = 1;
}

var waitForDescInterval = setInterval(() => {
if (document.querySelector('div#description') || (++tries * intervalMs >= maxIntervalMs)) {
clearInterval(waitForDescInterval);
}

if (this.storage.player_forced_playback_speed === true) {
if (player.getVideoData().isLive === false &&
(this.storage.player_force_speed_on_music === true ||
document.querySelector('h3#title')?.innerText !== 'Music' // (=buyable/registered music table)
|| (
(ImprovedTube.elements.category !== 'Music' && !/official (music )?video|lyrics|cover[\)\]]|[\(\[]cover|cover version|karaok|(sing|play)[- ]?along|卡拉OK|卡拉OK|الكاريوكيкараоке|カラオケ|노래방/i.test(ImprovedTube.elements.title + ImprovedTube.elements.keywords)
) || /do[ck]u|interv[iyj]|back[- ]?stage|インタビュー|entrevista|面试|面試|회견|wawancara|مقابلة|интервью|entretien|기록한 것|记录|記錄|ドキュメンタリ|وثائقي|документальный/i.test(ImprovedTube.elements.keywords + ImprovedTube.elements.title)
) // && location.href.indexOf('music') === -1 // (=only running on www.youtube.com anyways)
)) {
player.setPlaybackRate(Number(option));
video.playbackRate = Number(option);
} else {
player.setPlaybackRate(1);
if (this.storage.player_forced_playback_speed === true) {
var waitForDescInterval = setInterval(() => {
if (document.querySelector('div#description') || (++tries * intervalMs >= maxIntervalMs)) {
if (player.getVideoData().isLive === false) {
let category = document.querySelector('meta[itemprop=genre]')?.content;
let titlekeywords = document.getElementsByTagName('meta')?.title?.content + document.getElementsByTagName('meta')?.keywords?.content;
if (this.storage.player_force_speed_on_music === true // dont care if music, just switch it
|| (this.storage.player_force_speed_on_music === false // check if NOT music first
&& document.querySelector('h3#title')?.innerText !== 'Music' // (=buyable/registered music table)
&& category !== 'Music'
&& !(/official (music )?video|lyrics|cover[\)\]]|[\(\[]cover|cover version|karaok|(sing|play)[- ]?along|卡拉OK|卡拉OK|الكاريوكيкараоке|カラオケ|노래방/i.test(titlekeywords) && !/do[ck]u|interv[iyj]|back[- ]?stage|インタビュー|entrevista|面试|面試|회견|wawancara|مقابلة|интервью|entretien|기록한 것|记录|記錄|ドキュメンタリ|وثائقي|документальный/i.test(titlekeywords)) // says its music in description, but not backstage/interview? ugly hack!
// && location.href.indexOf('music') === -1 // (=only running on www.youtube.com anyways)
)) {
player.setPlaybackRate(Number(option));
video.playbackRate = Number(option);
} else { // Music and we are not overriding speed, set normal
player.setPlaybackRate(1);
video.playbackRate = 1;
}
}
clearInterval(waitForDescInterval);
}
}
}, intervalMs);
}, intervalMs);
} else {
player.setPlaybackRate(1);
video.playbackRate = 1;
}
};

ImprovedTube.playerForceSpeedOnMusic = function () {
ImprovedTube.playerPlaybackSpeed();
};
/*------------------------------------------------------------------------------
SUBTITLES
Expand Down

0 comments on commit 7b3020f

Please sign in to comment.