Skip to content

Instantly share code, notes, and snippets.

@teknogeek
Last active October 18, 2023 15:06
Show Gist options
  • Save teknogeek/62aaaba9d3eb5d5e11964968b0d6f53b to your computer and use it in GitHub Desktop.
Save teknogeek/62aaaba9d3eb5d5e11964968b0d6f53b to your computer and use it in GitHub Desktop.
A Greasemonkey Script to Whitelist YouTube Channels with uBlock Origin

NOTE: This script has been designed to work only with YouTube's new material design layout

How to Whitelist a Channel

Personally, I use uBlock Origin since it's faster, more efficient, and less biased than Adblock Plus. So, here are instructions on how to add a whitelist rule for a channel in uBlock

  1. Goto a YouTube video posted by the channel you want to whitelist
  2. Wait for it to load and copy the text following the &user= portion of the URL
  3. Click on the uBlock icon
  4. Click on the gear in the corner of the pop-up window
  5. Click on the "Whitelist" tab in the options page
  6. Add a new line to the list containing the following: youtube.com/*user=USER_ID BE SURE TO CHANGE USER_ID TO THE TEXT YOU COPIED EARLIER!
  7. For example, if you wanted to add Vet Ranch to your whitelist, you would add: youtube.com/*user=VetRanch
  8. Click the "Apply changes" button
  9. Reload the tab and you should notice uBlock is disabled

Caveat

There's always a caveat isn't there...since this is unable to get the channel information before the video starts playing, it is impossible to actually load an ad when the channel ID is initially gotten and put into the URL. To fix this, the script will reload the page automatically once it knows the channel ID to allow ads to load. Sorry!

// ==UserScript==
// @name YouTube Channel Whitelister
// @namespace https://tekno.pw
// @author teknogeek
// @description Helps whitelist YouTube channels in uBlock Origin
// @include http://*.youtube.com/*
// @include https://*.youtube.com/*
// @version 2.2
// @grant none
// @license http://creativecommons.org/licenses/by-sa/4.0/
// ==/UserScript==
function setChannelName(elem) {
// use regex to get the channel name or user ID from the element data (thanks @Google for the __data__ :D)
var channelID = elem.__data__.data.owner.videoOwnerRenderer.navigationEndpoint.browseEndpoint.canonicalBaseUrl;
channelID = channelID.match(/\/(?:user|channel)\/(.*)/);
if(channelID !== null) {
// check that the channel ID hasn't been added to the URL already
if(location.href.search('&user=') == -1) {
// if not, add it now
history.pushState({}, null, `${location.href}&user=${channelID[1]}`);
window.location.reload();
}
}
}
// add an observer to the page that will wait for dynamic page updates in order to properly work when a video is being loaded by JS
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes !== null) {
for (var i = 0; i < mutation.addedNodes.length; i++) {
var elem = mutation.addedNodes[i];
if(elem !== undefined && elem.tagName !== undefined) {
var elemTag = elem.tagName.toLowerCase();
if(elemTag == 'ytd-video-secondary-info-renderer') {
setChannelName(elem);
}
}
}
}
});
});
// add the observer to the document body
observer.observe(document.body, {childList: true, subtree: true});
@quantfreedom
Copy link

does this still work or how do i add to whitelist now ... i have literally tried this entire list on my trusted sites on ublock and it doesn't let adds play
@@youtube.com/channel=@coreyms
@@youtube.com/channel=@coreyms
@@youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/id=@coreyms
@@youtube.com/id=@coreyms
@@youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/user=@coreyms
@@youtube.com/user=@coreyms
@@youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/channel=@coreyms
@@youtube.com/channel=@coreyms

@@youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g

@@youtube.com/id=@coreyms
@@youtube.com/id=@coreyms

@@youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g

@@youtube.com/user=@coreyms
@@youtube.com/user=@coreyms

@@youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
@@youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g

*youtube.com/*channel=@coreyms
*youtube.com/channel=@coreyms
*youtube.com/*channel=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/*id=@coreyms
*youtube.com/id=@coreyms
*youtube.com/*id=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/*user=@coreyms
*youtube.com/user=@coreyms
*youtube.com/*user=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/channel=@coreyms
youtube.com/channel=@coreyms
*youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/id=@coreyms
youtube.com/id=@coreyms
*youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
*youtube.com/user=@coreyms
youtube.com/user=@coreyms
*youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/channel=@coreyms
youtube.com/channel=@coreyms
youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/id=@coreyms
youtube.com/id=@coreyms
youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/user=@coreyms
youtube.com/user=@coreyms
youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/channel=@coreyms
youtube.com/channel=@coreyms

youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/channel=UCCezIgC97PvUuR4_gbFUs5g

youtube.com/id=@coreyms
youtube.com/id=@coreyms

youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/id=UCCezIgC97PvUuR4_gbFUs5g

youtube.com/user=@coreyms
youtube.com/user=@coreyms

youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g
youtube.com/user=UCCezIgC97PvUuR4_gbFUs5g

if i am trying to add coreyms to white list how do i do that? https://www.youtube.com/@coreyms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment