diff --git a/package-lock.json b/package-lock.json index 67ab8d2a..b93279c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "youtube-webos", - "version": "0.3.3", + "version": "0.3.4", "license": "GPL-3.0-only", "dependencies": { "@babel/runtime-corejs3": "^7.24.4", diff --git a/src/config.js b/src/config.js index 1a7fd149..27c4bac0 100644 --- a/src/config.js +++ b/src/config.js @@ -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' } diff --git a/src/shorts.js b/src/shorts.js new file mode 100644 index 00000000..d927fb14 --- /dev/null +++ b/src/shorts.js @@ -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 + ); +} diff --git a/src/ui.js b/src/ui.js index 1779406e..e48ff4db 100644 --- a/src/ui.js +++ b/src/ui.js @@ -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'); diff --git a/src/userScript.js b/src/userScript.js index cd550219..df0f41c4 100644 --- a/src/userScript.js +++ b/src/userScript.js @@ -13,6 +13,7 @@ document.addEventListener( ); import './adblock.js'; +import './shorts.js'; import './sponsorblock.js'; import './ui.js';