Skip to content

youtube mainpage wont load problem solved #2842 #2860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
break

case 'tab-connected':
// Skip handling if the main page is already initialized
if (sender.tab.url === 'https://www.youtube.com/' && ImprovedTube.initializedHomePage) {
console.warn('ImprovedTube: Skipping redundant tab connection for the main page.');
return;
}
tabConnected[sender.tab.id] = true;
sendResponse({
tabId: sender.tab.id
Expand Down
9 changes: 8 additions & 1 deletion js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ ImprovedTube.pageType = function () {
document.documentElement.dataset.pageType = 'video';
} else if (location.pathname === '/') {
document.documentElement.dataset.pageType = 'home';

// Safeguard to prevent infinite reloads
if (ImprovedTube.initializedHomePage) {
console.warn('ImprovedTube: Home page already initialized. Skipping redundant operations.');
return;
}
ImprovedTube.initializedHomePage = true;
} else if (/\/subscriptions\?/.test(location.href)) {
document.documentElement.dataset.pageType = 'subscriptions';
} else if (/\/@|(\/(channel|user|c)\/)[^/]+(?!\/videos)/.test(location.href)) {
Expand Down Expand Up @@ -294,7 +301,7 @@ ImprovedTube.videoPageUpdate = function () {
};

ImprovedTube.playerOnPlay = function () {
HTMLMediaElement.prototype.play = (function (original) {
HTMLMediaElement.prototype.play = (function (original) {t
return function () {
if (!this.closest('#inline-preview-player')) {
this.removeEventListener('loadedmetadata', ImprovedTube.playerOnLoadedMetadata);
Expand Down