Skip to content

Commit 6e70202

Browse files
committed
[bugfix] 78 - hide top container with shorts instead of just inner one
1 parent b878004 commit 6e70202

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

manifest-chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"manifest_version": 3,
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"name": "__MSG_extensionName__",
55
"description": "__MSG_extensionDescription__",
66
"icons": {

manifest-firefox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"manifest_version": 2,
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"name": "__MSG_extensionName__",
55
"description": "__MSG_extensionDescription__",
66
"icons": {

src/main.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const REST_SHORTS_CONTAINERS_TAG = isMobile ? [
5050
// extendable shelf with shorts on Search page
5151
["grid-shelf-view-model"],
5252
// shelf containing multiple shorts on Home page
53-
["ytd-rich-shelf-renderer"],
53+
["ytd-rich-section-renderer:has(>div>ytd-rich-shelf-renderer)"],
5454
// container of videos on home/subscription page (so far only for shorts)
5555
["ytd-rich-grid-group"],
5656

@@ -268,16 +268,17 @@ function setup() {
268268
loadVariables(value);
269269

270270
hidingMethodsToExecute = []
271-
if (hideYTShortsVideos) {
272-
hidingMethodsToExecute.push(() => hideShorts(hideYTShortsVideos))
273-
}
274-
else {
275-
hideShorts(hideYTShortsVideos)
276-
}
277271

278272
combinedSelectorsToQuery = REST_SHORTS_CONTAINERS_TAG;
279273

280274
if (isMobile) {
275+
if (hideYTShortsVideos) {
276+
hidingMethodsToExecute.push(() => hideShortsMobile(hideYTShortsVideos))
277+
}
278+
else {
279+
hideShortsMobile(hideYTShortsVideos)
280+
}
281+
281282
if (hideYTShortsTab) {
282283
hidingMethodsToExecute.push(() => hideShortsTab(hideYTShortsTab))
283284
}
@@ -298,6 +299,13 @@ function setup() {
298299
{ childList: true, subtree: true });
299300
}
300301
else {
302+
if (hideYTShortsVideos) {
303+
hidingMethodsToExecute.push(() => hideShortsDesktop(hideYTShortsVideos))
304+
}
305+
else {
306+
hideShortsDesktop(hideYTShortsVideos)
307+
}
308+
301309
combinedSelectorsToQuery += "," + dHidingVideoRenderer.elementTagName;
302310
waitForElementTimeout("#page-manager", document.body, { timeout_ms: 5000 }).then((wrapperElement1) => {
303311
pageManagerNode = wrapperElement1;
@@ -413,7 +421,7 @@ function locationPathNameNodes() {
413421
return childrenInPageManagerWithoutKnownOnes();
414422
}
415423

416-
function hideShorts(hide = true) {
424+
function hideShortsDesktop(hide = true) {
417425
if (isLocationPathNameToIgnore())
418426
return;
419427

@@ -436,16 +444,6 @@ function hideShorts(hide = true) {
436444
else
437445
dHideVideoRendererSubscriptionPage.showShort(element);
438446
}
439-
else if (isMobile === true
440-
&& location.pathname.match(hidingShortsOnPathNames.homePage.reg)
441-
&& elementTagName.match(mHidingVideoRenderer.elementTagName)) {
442-
if (hide) {
443-
mHidingVideoRenderer.hideShort(element);
444-
}
445-
else {
446-
mHidingVideoRenderer.showShort(element);
447-
}
448-
}
449447
// other pages with containers on search page and channel's search
450448
else if (elementTagName.match(dHidingVideoRenderer.elementTagName)) {
451449
if (hide) {
@@ -472,6 +470,40 @@ function hideShorts(hide = true) {
472470
}
473471
}
474472

473+
function hideShortsMobile(hide = true) {
474+
if (isLocationPathNameToIgnore())
475+
return;
476+
477+
const nodes = locationPathNameNodes();
478+
for (let i = 0; i < nodes.length; i++) {
479+
let elements = nodes[i].querySelectorAll(combinedSelectorsToQuery);
480+
elements.forEach(element => {
481+
482+
const elementTagName = element.tagName.toLowerCase();
483+
484+
if (location.pathname.match(hidingShortsOnPathNames.homePage.reg)
485+
&& elementTagName.match(mHidingVideoRenderer.elementTagName)) {
486+
if (hide) {
487+
mHidingVideoRenderer.hideShort(element);
488+
}
489+
else {
490+
mHidingVideoRenderer.showShort(element);
491+
}
492+
}
493+
// hide whole shelf if just contains "yt[dm]-reel-item-renderer" tag. For now seems to be only used for yt-shorts videos
494+
// and hide any video container that contains a ref link to shorts
495+
else if ((elementTagName.match(SHELF_TAG_REGEX)
496+
&& element.querySelector(SHELF_ITEM_TAG_SELECTOR) != null)
497+
|| element.querySelector(SHORTS_HREF_SELECTOR) != null) {
498+
hideElement(hide, element, () => { dRearrangeVideosInGrid.execute(element) });
499+
}
500+
else if (hide) {
501+
hideNonShorts(element)
502+
}
503+
});
504+
}
505+
}
506+
475507
function hideNonShorts(element) {
476508
// Hide videos that are too short
477509
if (hidingShortVideosActive) {

0 commit comments

Comments
 (0)