Skip to content

Commit

Permalink
will HTMLMediaElement timeupdate run faster than 4hz?
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Apr 27, 2024
1 parent a25a724 commit 40aedd4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 44 deletions.
98 changes: 55 additions & 43 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ImprovedTube.childHandler = function (node) { //console.log(node.nodeName);
//console.log("node.nodeName:CHILD-"+i+":"+children[i].id+",class:"+children[i].className+","+children[i]+"("+children[i].nodeName+")");
i++;
}
}
}
}; */

ImprovedTube.ytElementsHandler = function (node) {
Expand All @@ -47,31 +47,31 @@ ImprovedTube.ytElementsHandler = function (node) {
this.blocklist('channel', node);
}
}
} /* else if (name === 'META') { //<META> infos are not updated when clicking related videos...
if(node.getAttribute('name')) {
//if(node.getAttribute('name') === 'title') {ImprovedTube.title = node.content;} //duplicate
//if(node.getAttribute('name') === 'description') {ImprovedTube.description = node.content;} //duplicate
//if node.getAttribute('name') === 'themeColor') {ImprovedTube.themeColor = node.content;} //might help our darkmode/themes
} /* else if (name === 'META') { //<META> infos are not updated when clicking related videos...
if(node.getAttribute('name')) {
//if(node.getAttribute('name') === 'title') {ImprovedTube.title = node.content;} //duplicate
//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;}
} 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') === 'channelId') {ImprovedTube.channelId = node.content;}
//if(node.getAttribute('itemprop') === 'videoId') {ImprovedTube.videoId = 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') === '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.
//if(node.getAttribute('itemprop') === 'description') {ImprovedTube.description = node.content;}
//if(node.getAttribute('itemprop') === 'duration') {ImprovedTube.duration = node.content;}
//if(node.getAttribute('itemprop') === 'interactionCount'){ImprovedTube.views = node.content;}
//if(node.getAttribute('itemprop') === 'isFamilyFriendly'){ImprovedTube.isFamilyFriendly = node.content;}
//if(node.getAttribute('itemprop') === 'unlisted') {ImprovedTube.unlisted = node.content;}
//if(node.getAttribute('itemprop') === 'regionsAllowed'){ImprovedTube.regionsAllowed = node.content;}
//if(node.getAttribute('itemprop') === 'paid') {ImprovedTube.paid = node.content;}
// if(node.getAttribute('itemprop') === 'datePublished' ){ImprovedTube.datePublished = node.content;}
//to use in the "how long ago"-feature, not to fail without API key? just like the "day-of-week"-feature above
// if(node.getAttribute('itemprop') === 'uploadDate') {ImprovedTube.uploadDate = node.content;}
}
} */
//if(node.getAttribute('itemprop') === 'description') {ImprovedTube.description = node.content;}
//if(node.getAttribute('itemprop') === 'duration') {ImprovedTube.duration = node.content;}
//if(node.getAttribute('itemprop') === 'interactionCount'){ImprovedTube.views = node.content;}
//if(node.getAttribute('itemprop') === 'isFamilyFriendly'){ImprovedTube.isFamilyFriendly = node.content;}
//if(node.getAttribute('itemprop') === 'unlisted') {ImprovedTube.unlisted = node.content;}
//if(node.getAttribute('itemprop') === 'regionsAllowed'){ImprovedTube.regionsAllowed = node.content;}
//if(node.getAttribute('itemprop') === 'paid') {ImprovedTube.paid = node.content;}
// if(node.getAttribute('itemprop') === 'datePublished' ){ImprovedTube.datePublished = node.content;}
//to use in the "how long ago"-feature, not to fail without API key? just like the "day-of-week"-feature above
// if(node.getAttribute('itemprop') === 'uploadDate') {ImprovedTube.uploadDate = node.content;}
}
} */
else if (name === 'YTD-TOGGLE-BUTTON-RENDERER' || name === 'YTD-PLAYLIST-LOOP-BUTTON-RENDERER') {
//can be precise previously node.parentComponent & node.parentComponent.parentComponent
if (node.closest("YTD-MENU-RENDERER")
Expand Down Expand Up @@ -264,11 +264,11 @@ ImprovedTube.ytElementsHandler = function (node) {
ImprovedTube.chapters(node);
}, 200);
} /* else if (name === 'TP-YT-PAPER-BUTTON') {
if ( (id === 'expand-sizer' || id === 'expand') && node.parentNode.id === 'description-inline-expander') {
setTimeout(function () {
ImprovedTube.expandDescription(node); console.log("EXPAND DESCRIPTION, OLD WAY")
}, 750);
}} */
if ( (id === 'expand-sizer' || id === 'expand') && node.parentNode.id === 'description-inline-expander') {
setTimeout(function () {
ImprovedTube.expandDescription(node); console.log("EXPAND DESCRIPTION, OLD WAY")
}, 750);
}} */
}

};
Expand Down Expand Up @@ -387,23 +387,35 @@ ImprovedTube.initPlayer = function () {
}
};

ImprovedTube.playerOnTimeUpdate = function () {
if (ImprovedTube.video_src !== this.src) {
ImprovedTube.video_src = this.src;

if (ImprovedTube.initialVideoUpdateDone !== true) {
ImprovedTube.playerQuality();
}
} else if (ImprovedTube.latestVideoDuration !== this.duration) {
ImprovedTube.latestVideoDuration = this.duration;
var timeUpdateInterval = null;
var noTimeUpdate = null;

ImprovedTube.playerQuality();
}
ImprovedTube.playerOnTimeUpdate = function() {
var currentTime = Date.now();
if (!timeUpdateInterval) {
timeUpdateInterval = setInterval(function() {
if (ImprovedTube.video_src !== this.src) {
ImprovedTube.video_src = this.src;

ImprovedTube.alwaysShowProgressBar();
ImprovedTube.playerRemainingDuration();
if (ImprovedTube.initialVideoUpdateDone !== true) {
ImprovedTube.playerQuality();
}
} else if (ImprovedTube.latestVideoDuration !== this.duration) {
ImprovedTube.latestVideoDuration = this.duration;

ImprovedTube.playerQuality();
}

ImprovedTube.played_time += .25;
ImprovedTube.alwaysShowProgressBar();
ImprovedTube.playerRemainingDuration();
ImprovedTube.played_time += .5;
}, 500);
}
clearInterval(noTimeUpdate);
noTimeUpdate = setTimeout(function() {
clearInterval(timeUpdateInterval);
timeUpdateInterval = null;
}, 987);
};

ImprovedTube.playerOnLoadedMetadata = function () {
Expand Down
2 changes: 1 addition & 1 deletion js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ ImprovedTube.playerAutofullscreen = function () {
QUALITY
------------------------------------------------------------------------------*/
ImprovedTube.playerQuality = function (quality) {
if (!quality) var quality = this.storage.player_quality;
if (!quality) quality = this.storage.player_quality;
if (quality && quality !== 'auto') {
var player = this.elements.player;
if (player && player.getAvailableQualityLevels && !player.dataset.defaultQuality) {
Expand Down

0 comments on commit 40aedd4

Please sign in to comment.