Skip to content

Commit da7f2b3

Browse files
SnektronVulpelo
authored andcommitted
add option to hide yt posts
1 parent 556c22c commit da7f2b3

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Extension's Chrome Web Store users](https://img.shields.io/chrome-web-store/users/ankepacjgoajhjpenegknbefpmfffdic?label=Chrome%20Users&logo=google%20chrome)](https://chrome.google.com/webstore/detail/hide-shorts-for-youtube/ankepacjgoajhjpenegknbefpmfffdic)
77
[![Licence](https://img.shields.io/github/license/Vulpelo/hide-youtube-shorts)](https://github.com/Vulpelo/hide-youtube-shorts/blob/master/LICENCE.md)
88

9-
Firefox add-on that hides YouTube-shorts videos from home page, subscriptions and search results.
9+
Firefox add-on that hides YouTube-shorts videos from home page, subscriptions and search results.
1010
Also allows you to hide "Shorts" tab.
1111

1212
## Features
@@ -20,6 +20,7 @@ Also allows you to hide "Shorts" tab.
2020
- Hiding live videos (experimental, off by default)
2121
- Hiding 'Upcoming' videos (experimental, off by default)
2222
- Redirect shorts to original video player (experimental, off by default)
23+
- Hiding posts (experimental, off by default)
2324

2425
## Installation
2526

@@ -33,7 +34,7 @@ Prepare files for chrome and firefox versions by running `npm run prepare` comma
3334

3435
You can also run `npm run zip` command to prepare and create zip archives for both chrome and firefox versions. Both will be placed in `./build` directory
3536

36-
### Firefox
37+
### Firefox
3738

3839
Add the Add-on temporarily:
3940
1. In Firefox browser go to the debugging page by typing in url <b>[about:debugging#/runtime/this-firefox](about:debugging#/runtime/this-firefox)</b>
@@ -54,7 +55,7 @@ Add the Add-on manually:
5455

5556
# FAQ
5657
- Going "Back" in navigation again redirects tab to the original video player
57-
- Chrome and Firefox on Android don't support [loadReplace option](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/update), meaning that clicking "Back" button will direct to the original video URL (not the page from which video was clicked on). This will then again redirect the page. You can click and hold the back button to display list of previous pages and select desired page from here.
58+
- Chrome and Firefox on Android don't support [loadReplace option](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/update), meaning that clicking "Back" button will direct to the original video URL (not the page from which video was clicked on). This will then again redirect the page. You can click and hold the back button to display list of previous pages and select desired page from here.
5859
- After addon installation shorts are still visible on youtube's page
5960
- It is also required to refresh the youtube's page in order for the scripts to load.
6061
- After a while youtube starts slowing down

_locales/en/messages.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extensionName": {"message": "Hide shorts for Youtube™"},
33
"extensionDescription": {"message": "Hides shorts from YouTube™ from home page, subscriptions and search results."},
4-
4+
55
"cfg_hide_videos": {"message": "Hide Shorts videos"},
66
"cfg_hide_tab": {"message": "Hide Shorts tab"},
77
"cfg_hide_notifications": {"message": "Hide Shorts notifications"},
@@ -10,7 +10,7 @@
1010
"setting_experimental_text": {"message": "Experimental"},
1111
"settings_hiding_on_text": {"message": "Hiding on"},
1212
"settings_performance_text": {"message": "Performance"},
13-
13+
1414
"cfg_hide_videos_home": {"message": "Home page"},
1515
"cfg_hide_videos_subscription": {"message": "Subscriptions page"},
1616
"cfg_hide_videos_search": {"message": "Search page"},
@@ -27,5 +27,6 @@
2727

2828
"cfg_hide_live_videos": {"message": "Hide Live videos"},
2929
"cfg_hide_upcoming_videos": {"message": "Hide 'Upcoming' videos"},
30-
"cfg_shorts_in_original_video_player": {"message": "Redirect to original video player"}
30+
"cfg_shorts_in_original_video_player": {"message": "Redirect to original video player"},
31+
"cfg_hide_posts": {"message": "Hide posts"}
3132
}

src/main.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ let hidingShortsTimeoutTimeMs = 500;
1717
let hidingShortVideosActive = false;
1818
let hidingShortVideosTimeSeconds = 20;
1919

20+
let hideYTPosts = false
21+
2022
const isMobile = location.hostname == "m.youtube.com";
2123

2224
const hidingShortsOnPathNames = {
@@ -42,12 +44,14 @@ const REST_SHORTS_CONTAINERS_TAG = isMobile ? [
4244
["ytm-grid-video-renderer"],
4345
// videos on Search page and Video page
4446
["ytm-video-with-context-renderer"],
47+
// posts
48+
["ytm-backstage-post-thread-renderer"],
4549
].join(",") : [
4650
// shelf containing multiple shorts on Search page
4751
["ytd-reel-shelf-renderer"],
48-
// extendable shelf with shorts on Search page
52+
// extendable shelf with shorts on Search page
4953
["grid-shelf-view-model"],
50-
// shelf containing multiple shorts on Home page
54+
// shelf containing multiple shorts on Home page
5155
["ytd-rich-shelf-renderer"],
5256
// container of videos on home/subscription page (so far only for shorts)
5357
["ytd-rich-grid-group"],
@@ -64,10 +68,11 @@ const REST_SHORTS_CONTAINERS_TAG = isMobile ? [
6468
/* ON MOBILE */
6569
// videos in ytm-rich-section-renderer on Home page
6670
const mHidingVideoRenderer = new HidingShortsWithContainer("ytm-shorts-lockup-view-model", "ytm-rich-section-renderer");
71+
const MOBILE_POSTS_RENDERER = "ytm-backstage-post-thread-renderer";
6772

6873
/* ON DESKTOP */
6974
const dRearrangeVideosInGrid = new RearrangeVideosInGrid();
70-
// hiding videos on Search page, videos in list mode on subscription page
75+
// hiding videos on Search page, videos in list mode on subscription page
7176
const dHidingVideoRenderer = new HidingShortsWithContainer("ytd-video-renderer", "ytd-shelf-renderer");
7277
// hiding videos on subscription page in list mode
7378
const dHideVideoRendererSubscriptionPage = new HidingShortsWithContainer("ytd-video-renderer", "ytd-item-section-renderer");
@@ -178,6 +183,11 @@ function loadVariables(value) {
178183
if (value.hidingUpcomingVideosActive === true)
179184
hidingVideoTypes.push(UPCOMING)
180185

186+
if (value.hidingPostsActive == undefined)
187+
chrome.storage.local.set({ hidingPostsActive: hideYTPosts });
188+
else
189+
hideYTPosts = value.hidingPostsActive;
190+
181191
if (value.hideYTShortsVideos == undefined)
182192
chrome.storage.local.set({ hideYTShortsVideos: hideYTShortsVideos });
183193
else
@@ -247,6 +257,7 @@ function setup() {
247257
loadVariables(value);
248258

249259
combinedSelectorsToQuery = REST_SHORTS_CONTAINERS_TAG;
260+
250261
if (isMobile) {
251262
combinedSelectorsToQuery += "," + mHidingVideoRenderer.elementTagName
252263
hideShortsCallbackInner =
@@ -438,8 +449,11 @@ function hideNonShorts(element) {
438449
hideVideoIfBelowLength(element, hidingShortVideosTimeSeconds)
439450
}
440451
// Hide videos of type
441-
if (hidingVideoTypes.length > 0)
452+
if (hidingVideoTypes.length > 0)
442453
hideVideoIfOfType(hidingVideoTypes, element)
454+
455+
if (element.tagName.toLowerCase() == MOBILE_POSTS_RENDERER)
456+
hideElement(hideYTPosts, element);
443457
}
444458

445459
function hideVideoIfOfType(types, element) {

src/menu/popup.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h2>Hide Youtube-Shorts</h2>
1818
<legend id="settings_text">
1919
Options
2020
</legend>
21-
21+
2222
<label class="setting">
2323
<input type="checkbox" id="hideYTShortsVideosInput">
2424
<span id="hide_videos_text" class="switchLabel" title="">
@@ -147,6 +147,13 @@ <h2>Hide Youtube-Shorts</h2>
147147
Redirect original video player
148148
</span>
149149
</label>
150+
<br>
151+
<label class="setting">
152+
<input type="checkbox" id="hidingPostsCheckbox">
153+
<span id="hide_posts_text" class="switchLabel">
154+
Hide posts
155+
</span>
156+
</label>
150157
</fieldset>
151158
</div>
152159
</div>
@@ -165,4 +172,4 @@ <h2>Hide Youtube-Shorts</h2>
165172
<script src="permissions.js"></script>
166173
<script src="popup.js"></script>
167174
</body>
168-
</html>
175+
</html>

src/menu/popup.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ window.onload = function () {
5454
chrome.storage.local.set({ hideYTShortsVideosOnChannelPage: e.target.checked });
5555
})
5656

57-
// close button for shelf on subscription page
57+
// close button for shelf on subscription page
5858
const subscriptionShelfCloseButtonInputCheckbox = document.getElementById("subscriptionShelfCloseButtonInputCheckbox");
5959
if (value.subscriptionShelfCloseButton != undefined)
6060
subscriptionShelfCloseButtonInputCheckbox.checked = value.subscriptionShelfCloseButton;
@@ -126,6 +126,15 @@ window.onload = function () {
126126
hidingUpcomingVideosInputCheckbox.addEventListener("input", function (e) {
127127
chrome.storage.local.set({ hidingUpcomingVideosActive: e.target.checked });
128128
})
129+
130+
// hiding posts
131+
const hidingPostsCheckbox = document.getElementById("hidingPostsCheckbox");
132+
if (value.hidingPostsActive != undefined)
133+
hidingPostsCheckbox.checked = value.hidingPostsActive;
134+
hidingPostsCheckbox.addEventListener("input", function (e) {
135+
chrome.storage.local.set({ hidingPostsActive: e.target.checked });
136+
})
137+
129138
});
130139

131140
// Set language
@@ -153,6 +162,7 @@ window.onload = function () {
153162
document.getElementById("hide_live_videos_text").textContent = chrome.i18n.getMessage("cfg_hide_live_videos");
154163
document.getElementById("hide_upcoming_videos_text").textContent = chrome.i18n.getMessage("cfg_hide_upcoming_videos");
155164
document.getElementById("shorts_in_original_video_player_text").textContent = chrome.i18n.getMessage("cfg_shorts_in_original_video_player");
165+
document.getElementById("hide_posts_text").textContent = chrome.i18n.getMessage("cfg_hide_posts");
156166

157167
// version
158168
let manifestData = chrome.runtime.getManifest();

0 commit comments

Comments
 (0)