Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove shorts from Subscriptions tab #201

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const CONFIG_KEY = 'ytaf-configuration';

const configOptions = new Map([
['enableAdBlock', { default: true, desc: 'Enable ad blocking' }],
['removeShorts', { default: true, desc: 'Remove Shorts from subscriptions' }],
['enableSponsorBlock', { default: true, desc: 'Enable SponsorBlock' }],
[
'enableSponsorBlockSponsor',
Expand Down
44 changes: 44 additions & 0 deletions src/shorts.js
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;
}
1 change: 1 addition & 0 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function createOptionsPanel() {

elmContainer.appendChild(createConfigCheckbox('enableAdBlock'));
elmContainer.appendChild(createConfigCheckbox('hideLogo'));
elmContainer.appendChild(createConfigCheckbox('removeShorts'));
JaCzekanski marked this conversation as resolved.
Show resolved Hide resolved
elmContainer.appendChild(createConfigCheckbox('enableSponsorBlock'));

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