Skip to content

Commit

Permalink
shorts: Remove shorts from Subscriptions tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Sep 18, 2024
1 parent cacdf6c commit 219c7eb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CONFIG_KEY = 'ytaf-configuration';
const configOptions = new Map([
['enableAdBlock', { default: true, desc: 'Enable ad blocking' }],
['enableSponsorBlock', { default: true, desc: 'Enable SponsorBlock' }],
['removeShorts', { default: true, desc: 'Remove Shorts from subscriptions' }],
[
'enableSponsorBlockSponsor',
{ default: true, desc: 'Skip sponsor segments' }
Expand Down
35 changes: 35 additions & 0 deletions src/shorts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint no-redeclare: 0 */
/* global fetch:writable */
import { configRead } from './config';

const origParse = JSON.parse;
JSON.parse = function () {
const r = origParse.apply(this, arguments);
if (!configRead('removeShorts')) {
return r;
}

// First page of subscriptions tab
const gridRenderer =
r?.contents?.tvBrowseRenderer?.content?.tvSecondaryNavRenderer?.sections[0]
?.tvSecondaryNavSectionRenderer?.tabs[0]?.tabRenderer?.content
?.tvSurfaceContentRenderer?.content?.gridRenderer;

if (gridRenderer?.items) {
removeShorts(gridRenderer);
}

// Pagination
const gridContinuation = r?.continuationContents?.gridContinuation;
if (gridContinuation?.items) {
removeShorts(gridContinuation);
}

return r;
};

function removeShorts(gridRenderer) {
gridRenderer.items = gridRenderer.items.filter(
(elm) => elm?.tileRenderer?.onSelectCommand?.reelWatchEndpoint == null
);
}
1 change: 1 addition & 0 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ function createOptionsPanel() {
elmContainer.appendChild(createConfigCheckbox('enableAdBlock'));
elmContainer.appendChild(createConfigCheckbox('hideLogo'));
elmContainer.appendChild(createConfigCheckbox('enableSponsorBlock'));
elmContainer.appendChild(createConfigCheckbox('removeShorts'));

const elmBlock = document.createElement('blockquote');

Expand Down
1 change: 1 addition & 0 deletions src/userScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ document.addEventListener(
);

import './adblock.js';
import './shorts.js';
import './sponsorblock.js';
import './ui.js';

Expand Down

0 comments on commit 219c7eb

Please sign in to comment.