generated from JohnBra/vite-web-extension
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into all-contributors/add-HelloIamarandomperson
- Loading branch information
Showing
30 changed files
with
888 additions
and
1,050 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { Nullable } from "@/src/types"; | ||
import { waitForSpecificMessage } from "@/src/utils/utilities"; | ||
|
||
let recommendationsObserver: Nullable<MutationObserver> = null; | ||
let observerDisabled = false; | ||
|
||
export async function enableHidePlaylistRecommendationsFromHomePage() { | ||
const { | ||
data: { | ||
options: { enable_hide_playlist_recommendations_from_home_page }, | ||
}, | ||
} = await waitForSpecificMessage("options", "request_data", "content"); | ||
|
||
if (!enable_hide_playlist_recommendations_from_home_page) return; | ||
|
||
hideRecommendations(); | ||
observeHomePageRecommendations(); | ||
} | ||
|
||
export function disableHidePlaylistRecommendationsFromHomePage() { | ||
showRecommendations(); | ||
|
||
if (recommendationsObserver) { | ||
recommendationsObserver.disconnect(); | ||
recommendationsObserver = null; | ||
} | ||
} | ||
|
||
function observeHomePageRecommendations() { | ||
const homePageObserver = new MutationObserver((mutations) => { | ||
if (observerDisabled) return; | ||
|
||
mutations.forEach((mutation) => { | ||
if (mutation.addedNodes.length) { | ||
Array.from(mutation.addedNodes).forEach((node) => { | ||
if (node instanceof HTMLElement && node.tagName === "YTD-RICH-ITEM-RENDERER") { | ||
hideMixRecommendation(node); | ||
} else if (node instanceof HTMLElement) { | ||
node.querySelectorAll<HTMLElement>("ytd-rich-item-renderer").forEach(hideMixRecommendation); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
if (hasRecommendationsOnHomePage()) { | ||
hideRecommendations(); | ||
} | ||
}); | ||
|
||
homePageObserver.observe(document.body, { childList: true, subtree: true }); | ||
recommendationsObserver = homePageObserver; | ||
} | ||
|
||
function hideMixRecommendation(element: HTMLElement) { | ||
if (element.querySelector("yt-collection-thumbnail-view-model")) { | ||
element.style.display = "none"; | ||
} | ||
} | ||
|
||
function toggleRecommendationsVisibility(recommendationsVisible: boolean) { | ||
// Use requestAnimationFrame to ensure synchronization | ||
requestAnimationFrame(() => { | ||
observerDisabled = !recommendationsVisible; | ||
|
||
const richItemRenderers = document.querySelectorAll<HTMLElement>("ytd-rich-item-renderer"); | ||
richItemRenderers.forEach((item) => { | ||
const mixThumbnail = item.querySelector("yt-collection-thumbnail-view-model"); | ||
if (mixThumbnail) { | ||
item.style.display = recommendationsVisible ? "" : "none"; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function hideRecommendations() { | ||
toggleRecommendationsVisibility(false); | ||
} | ||
|
||
function showRecommendations() { | ||
toggleRecommendationsVisibility(true); | ||
} | ||
|
||
function hasRecommendationsOnHomePage(): boolean { | ||
return document.querySelector("ytd-rich-grid-renderer #contents ytd-rich-item-renderer") !== null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.