forked from FriedChickenButt/youtube-webos
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from JaCzekanski/shorts-block
Remove shorts from Subscriptions tab
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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,44 @@ | ||
/* 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 = findFirstObject(r, 'gridRenderer'); | ||
if (gridRenderer?.items) { | ||
removeShorts(gridRenderer); | ||
} | ||
|
||
// Pagination | ||
const gridContinuation = findFirstObject(r, 'gridContinuation'); | ||
if (gridContinuation?.items) { | ||
removeShorts(gridContinuation); | ||
} | ||
|
||
return r; | ||
}; | ||
|
||
function removeShorts(container) { | ||
container.items = container.items.filter( | ||
(elm) => elm?.tileRenderer?.onSelectCommand?.reelWatchEndpoint == null | ||
); | ||
} | ||
|
||
function findFirstObject(haystack, needle) { | ||
for (const key in haystack) { | ||
if (key === needle) { | ||
return haystack[key]; | ||
} | ||
if (typeof haystack[key] === 'object') { | ||
const result = findFirstObject(haystack[key], needle); | ||
if (result) return result; | ||
} | ||
} | ||
return 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
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