Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ extension.events.on('init', function () {
extension.features.comments();
extension.features.openNewTab();
extension.features.removeListParamOnNewTab();
// extension.features.hideSponsoredVideosOnHome?.();
// extension.features.hideSponsoredVideosOnHome?.();
extension.features.channelBlocker?.();

bodyReady();
});

Expand Down
70 changes: 70 additions & 0 deletions js&css/extension/www.youtube.com/features/channel-blocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
(function () {
console.log("Channel blocker (allowed channels) loaded");

const allowedChannels = ["/@pantelisstavroulakis5456"];

function getChannelHref(video) {
// Look in multiple possible locations for the channel link
const possible = [
'ytd-channel-name a',
'#channel-name a',
'a[href^="/@"]'
];
for (const sel of possible) {
const el = video.querySelector(sel);
if (el) return el.getAttribute("href");
}
return null;
}

function filterVideos(videos) {
videos.forEach(video => {
const href = getChannelHref(video);
if (!href || !allowedChannels.includes(href)) {
video.style.display = "none"; // hide not allowed
} else {
video.style.display = ""; // show allowed
}
});
}

function scanFeed() {
// Most feed videos
const videos = document.querySelectorAll(
"ytd-rich-item-renderer, ytd-video-renderer, ytd-grid-video-renderer"
);
filterVideos(videos);
}

function startObserver() {
const root = document.querySelector("ytd-app") || document.body;
if (!root) {
console.log("Waiting for YouTube root...");
setTimeout(startObserver, 1000);
return;
}

console.log("Main feed detected — filtering active.");
scanFeed(); // initial scan

// Watch for newly added videos
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (
node.nodeType === 1 &&
(node.tagName === "YTD-RICH-ITEM-RENDERER" ||
node.tagName === "YTD-VIDEO-RENDERER" ||
node.tagName === "YTD-GRID-VIDEO-RENDERER")
) {
filterVideos([node]);
}
});
});
});

observer.observe(root, { childList: true, subtree: true });
}

startObserver();
})();
60 changes: 16 additions & 44 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"short_name": "ImprovedTube",
"name": "'Improve YouTube!' 🎧 (for YouTube & Videos)",
"short_name": "ImprovedTube",
"description": "__MSG_description_ext__",
"version": "4",
"default_locale": "en",
Expand All @@ -11,14 +11,9 @@
"32": "menu/icons/32.png",
"48": "menu/icons/48.png"
},
"browser_specific_settings": {
"gecko": {
"id": "{3c6bf0cc-3ae2-42fb-9993-0d33104fdcaf}"
}
"background": {
"service_worker": "background.js"
},
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "menu/index.html",
"default_area": "navbar"
Expand All @@ -29,7 +24,17 @@
},
"content_scripts": [
{
"all_frames": true,
"matches": ["https://www.youtube.com/*"],
"js": [
"js&css/extension/core.js",
"js&css/extension/functions.js",
"js&css/extension/www.youtube.com/night-mode/night-mode.js",
"js&css/extension/www.youtube.com/general/general.js",
"js&css/extension/www.youtube.com/appearance/sidebar/sidebar.js",
"js&css/extension/www.youtube.com/appearance/comments/comments.js",
"js&css/extension/init.js",
"js&css/extension/www.youtube.com/features/channel-blocker.js"
],
"css": [
"js&css/extension/www.youtube.com/styles.css",
"js&css/extension/www.youtube.com/night-mode/night-mode.css",
Expand All @@ -44,43 +49,10 @@
"https://www.youtube.com/audiolibrary/*",
"https://www.youtube.com/tv*"
],
"js": [
"js&css/extension/core.js",
"js&css/extension/functions.js",
"js&css/extension/www.youtube.com/night-mode/night-mode.js",
"js&css/extension/www.youtube.com/general/general.js",
"js&css/extension/www.youtube.com/appearance/sidebar/sidebar.js",
"js&css/extension/www.youtube.com/appearance/comments/comments.js",
"js&css/extension/init.js"
],
"matches": ["https://www.youtube.com/*"],
"run_at": "document_start"
}
],
"host_permissions": ["https://www.youtube.com/*"],
"optional_permissions": ["downloads"],
"permissions": ["contextMenus", "storage"],
"web_accessible_resources": [
{
"resources": [
"menu/index.html",
"js&css/web-accessible/core.js",
"js&css/web-accessible/functions.js",
"js&css/web-accessible/www.youtube.com/appearance.js",
"js&css/web-accessible/www.youtube.com/player.js",
"js&css/web-accessible/www.youtube.com/themes.js",
"js&css/web-accessible/www.youtube.com/playlist.js",
"js&css/web-accessible/www.youtube.com/playlist-complete-playlist.js",
"js&css/web-accessible/www.youtube.com/playlist-cleaner.js",
"js&css/web-accessible/www.youtube.com/channel.js",
"js&css/web-accessible/www.youtube.com/shortcuts.js",
"js&css/web-accessible/www.youtube.com/blocklist.js",
"js&css/web-accessible/www.youtube.com/settings.js",
"js&css/web-accessible/www.youtube.com/last-watched-overlay.js",
"js&css/web-accessible/init.js",
"menu/icons/48.png"
],
"matches": ["https://www.youtube.com/*"]
}
]
"permissions": ["storage", "contextMenus"],
"optional_permissions": ["downloads"]
}