Youtube Channel whitelist

Discussion in 'Feature Requests (Browser Extensions)' started by kurtextrem, May 13, 2014.

  1. kurtextrem

    kurtextrem New Member

    Joined:
    Apr 18, 2014
    Messages:
    4
    Adblock for Chrome introduced a new feature in version 2.6.33, which is a Youtube Channel Whitelist. The idea is pretty nice, as Youtube is a popular site which many users visit and therefore have their favorite 'Youtubers'. The only thing which is very difficult to decide is, allow ads on every youtube page (to support your favorite one) or not. Adblock solved that question now, you visit one video of your favorite Youtuber and add him to the Youtube Whitelist (using the popup). The source code is this one: (just to give you the idea)
    Code:
    if (/youtube/.test(document.location.hostname)) {  
      // Get actual URL
      var url = document.location.href;
      
      // Get enabled settings everytime in Safari
      if (SAFARI) {
        var enabled_settings = [];
        BGcall("get_settings", function(settings) {
          for (setting in settings) {
            if (settings[setting])
              enabled_settings.push(setting);
          }
          if (enabled_settings.indexOf("youtube_channel_whitelist") >= 0) 
            channel();
        });
      } else {
        channel();
      }
      
      // Function which: - grabs the name of the channel from the page
      //                 - puts the name of the channel on the end of the URL e.g. &channel=nameofthechannel
      //                 - reload the page, so AdBlock can properly whitelist the channel
      //                   (if channel is whitelisted by user)
      function channel() {
        if ((url.search("channel=") < 0) && (/channel\/|watch/.test(url)) && (url.search("feed") < 0)) {           
          if (/channel/.test(url)) {
            var get_yt_name = document.querySelector(".epic-nav-item-heading").innerText;
            if (get_yt_name === null) {
              get_yt_name = document.querySelector(".qualified-channel-title-text a[href*='/user/']");
              var extracted_name = get_yt_name.getAttribute("href").split('/').pop();
            } else {
              var extracted_name = get_yt_name.replace(/\s/g, '');
            }
            var new_url = url+"?&channel="+extracted_name;
          } else {
            var get_yt_name = document.querySelector("#watch7-user-header a[href*='/user/']");
            if (get_yt_name === null) { 
              //in Safari 5, the anchor has a different parent tag
              get_yt_name = document.querySelector("#ud a[href*='/user/']");
            }
            if (get_yt_name === null) {
              return;
            }
            var extracted_name = get_yt_name.getAttribute("href").split('/').pop();
            var new_url = url+"&channel="+extracted_name;
          }
          // Add the name of the channel to the end of URL
          window.history.replaceState(null,null,new_url);
          // Reload page from cache
          document.location.reload(false);
        }
      }
    }
    It would be VERY cool to have this in Adguard as well. (Note: I wouldn't implement that exact code, as it seems to reload every youtube video page... which is annoying. It should only reload if the channel name is in the whitelist.)

    By the way, I'm still not sure if there is any progress regarding "Open source". I'd love to contribute to Adguard as I know Chrome and Javascript (+ Chrome extensions) very well.
     
    Last edited by a moderator: May 13, 2014
  2. avatar

    avatar Administrator Staff Member Administrator

    Joined:
    Oct 26, 2010
    Messages:
    12,791
    It's rather simple to create a userscript that could do it.
    This userscript could use Adguard's API function AG_addRule to add an exception rule to our list.