Xtube Enhancer - Animated Thumbnails, Inline Video Loading, and Sponsor/Premium-Free Videos

Animates thumbnails, inlines video loading, and cleans up sponsored content

נכון ליום 16-01-2016. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Xtube Enhancer - Animated Thumbnails, Inline Video Loading, and Sponsor/Premium-Free Videos
// @description  Animates thumbnails, inlines video loading, and cleans up sponsored content
// @namespace    xtube
// @version      0.9
// @include      http*://www.xtube.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/lodash-compat/3.10.1/lodash.min.js
// @run-at document-end
// ==/UserScript==
$(document).ready(function() {
  $('div.advertisement').remove();
  $('a.clearfix').remove();
  $('li.pull-right').remove();
  $('h2.h1').remove();
  $('section.overviewPage>div:nth-child(5)').remove();
  // Remove premium content in index.
  $('div.col-xs-24>ul>li').each(function() {
    if ($(this).find('article>a>span>span').text() === 'Premium') {
      $(this).remove();
    }
  });
  // Remove sponsored content in index.
  $('section.overviewPage>div>ul>li').each(function() {
    if ($(this).find('article>dl>dd>a').text() === 'xtube_sponsor') {
      $(this).remove();
    }
  });
  // Remove sponsored content in search results.
  $('section.row>div>div>ul>li').each(function() {
    if ($(this).find('article>dl>dd>a').text() === 'xtube_sponsor') {
      $(this).remove();
    }
  });
  // Remove premium content below query index.
  $('div.mainContent>ul>li').each(function() {
    if ($(this).find('article>a>span>span').text() === 'Premium' || $(this).find('article>a>div>span>span').text() === 'Premium') {
      $(this).remove();
    }
  });
  // Remove sponsored content beside video player.
  var relatedVideos = null;
  $('div#related_videos>div').each(function() {
    relatedVideos = $(this).text().split(' ');
    for (var i = relatedVideos.length - 1; i >= 0; i--) {
      if (relatedVideos[i] === '0:15') {
        $(this).prev().remove();
        $(this).remove();
      }
    }
  });
  // Remove sponsored content below video player.
  $('div#watchPageLeft>div>div').each(function() {
    if ($(this).find('a>span:nth-child(3)').text() === '0:15') {
      $(this).remove();
    }
  });
  // Remove sponsored content in full related videos view.
  $('div.Card-list>article').each(function() {
    if ($(this).find('div>div>div:nth-child(3)').text() === '0:15') {
      $(this).remove();
    }
  });
  // New sponsored content formatting
  $('#mainSection > section > div > ul > li').each(function() {
    if ($(this).find('article > a:nth-child(1) > div > span.metaInfo > span.premiumLabel').text().includes('Premium')) {
      $(this).remove();
    }
  });
  $('#mainSection > section > div > div > ul > li').each(function() {
    if ($(this).find('article > a.userLink.ellipsis').text().includes('xtube_sponsor')) {
      $(this).remove();
    }
  });
  $('#mainSection > section > div.mainContent > ul > li').each(function() {
    if ($(this).find('article > a.userLink.ellipsis').text().includes('xtube_sponsor')) {
      $(this).remove();
    }
  });
  var cleanVidPage = function() {
    var spam = [];
    $('#related_videos > div').each(function() {
      if ($(this).find('a.username').text().includes('xtube_sponsor')) {
        $(this).prev().remove();
        $(this).remove();
        spam.push($(this).find('a.underline.font_b_12px').text());
      }
    });

    $('#watchPageLeft > div:nth-child(3)').children().each(function() {
      for (var x = 0; x < spam.length; x++) {
        if (spam[x] === $(this).find('a > span:nth-child(1)').text() || $(this).find('a > span:nth-child(1)').text().includes('.com')) {
          $(this).remove();
        }
      }
    });
  }
  cleanVidPage();
  var animateWatchPageLeft = function() {
    var watchPageLeft = $('#watchPageLeft > div > div > a > img');
    if (watchPageLeft.length > 0) {
      watchPageLeft.each(function(i, el) {
        var clone = $(el).clone();
        clone.insertBefore($(el));
        $(el).hide();
        var animation = [];
        var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'];
        var src = $(this).attr('src').split('/');
        if (_.last(src).length <= 6) {
          var src3 = _.without(src, _.last(src));
          var imgSrc = src3.join('/') + '/';
          for (var z = 0; z < images.length; z++) {
            animation.push(imgSrc + images[z]);
          }
          var n = -1;
          var animate = function() {
            clone.attr({
              src: animation[++n]
            });
            if (n === 14) {
              n = -1;
            }
            setTimeout(animate, 500);
          }.bind(this);
          animate();
        }
      });
    }
  }
  var animateRelatedVideos = function() {
      var relatedVideos = $('#related_videos > div > a > img');
      if (relatedVideos.length > 0) {
        relatedVideos.each(function(i, el) {
          var clone = $(el).clone();
          clone.insertBefore($(el));
          $(el).hide();
          var animation = [];
          var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'];
          var src = $(this).attr('src').split('/');
          if (_.last(src).length <= 6) {
            var src3 = _.without(src, _.last(src));
            var imgSrc = src3.join('/') + '/';
            for (var z = 0; z < images.length; z++) {
              animation.push(imgSrc + images[z]);
            }
            var n = -1;
            var animate = function() {
              clone.attr({
                src: animation[++n]
              });
              if (n === 14) {
                n = -1;
              }
              setTimeout(animate, 500);
            }.bind(this);
            animate();
          }
        });
      }
    }
    // Animate thumbnails
  _.delay(function() {
    var mainContent = $('div.mainContent>ul>li>article>a>div>div>img');
    if (mainContent.length > 0) {
      mainContent.each(function(i, el) {
        var clone = $(el).clone();
        clone.insertBefore($(el));
        $(el).hide();
        var animation = [];
        var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'];
        var src = $(this).attr('src').split('/');
        if (_.last(src).length <= 6) {
          var src3 = _.without(src, _.last(src));
          var imgSrc = src3.join('/') + '/';
          for (var z = 0; z < images.length; z++) {
            animation.push(imgSrc + images[z]);
          }
          var n = -1;
          var animate = function() {
            clone.attr({
              src: animation[++n]
            });
            if (n === 14) {
              n = -1;
            }
            setTimeout(animate, 500);
          }.bind(this);
          animate();
        }
      });
    }
    animateRelatedVideos();
    animateWatchPageLeft();
    var userPage = $('[id*="vid_id_"]');
    if (userPage.length > 0) {
      userPage.each(function(i, el) {
        var clone = $(el).clone();
        clone.insertBefore($(el));
        $(el).hide();
        var animation = [];
        var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'];
        var src = $(this).attr('src').split('/');
        if (_.last(src).length <= 6) {
          var src3 = _.without(src, _.last(src));
          var imgSrc = src3.join('/') + '/';
          for (var z = 0; z < images.length; z++) {
            animation.push(imgSrc + images[z]);
          }
          var n = -1;
          var animate = function() {
            clone.attr({
              src: animation[++n]
            });
            if (n === 14) {
              n = -1;
            }
            setTimeout(animate, 500);
          }.bind(this);
          animate();
        }
      });
    }
    var userFavorites = $('[id*="2_frame"]> a > img');
    if (userFavorites.length > 0) {
      userFavorites.each(function(i, el) {
        var clone = $(el).clone();
        clone.insertBefore($(el));
        $(el).hide();
        var animation = [];
        var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg', '15.jpg'];
        var src = $(this).attr('src').split('/');
        if (_.last(src).length <= 6) {
          var src3 = _.without(src, _.last(src));
          var imgSrc = src3.join('/') + '/';
          for (var z = 0; z < images.length; z++) {
            animation.push(imgSrc + images[z]);
          }
          var n = -1;
          var animate = function() {
            clone.attr({
              src: animation[++n]
            });
            if (n === 14) {
              n = -1;
            }
            setTimeout(animate, 500);
          }.bind(this);
          animate();
        }
      });
    }
  }, 4000);
  var related = $('#related_videos > div > a.underline.font_b_12px');
  var more = $('#watchPageLeft>div:nth-child(3)>div>a');
  var inlineVids = function(opt) {
    if (opt.length > 0) {
      opt.each(function(i, el) {
        $(el).click(function(e) {
          e.preventDefault();
          var vid = $('#watchPageLeft');
          var pageLeftClone = $('#watchPageLeft > div:nth-child(3)').clone();
          vid.empty();
          $('<iframe />').attr({
            'src': $(el).attr('href'),
            'frameborder': '0',
            'width': window.innerWidth / 1.2,
            'height': window.innerHeight
          }).appendTo(vid);
          var iframe = vid.find('iframe');
          iframe.hide();
          iframe.on('load', function() {
            iframe.contents().find('#watchPageLeft').appendTo(vid);
            pageLeftClone.children().appendTo('#watchPageLeft > div:nth-child(3)');
            iframe.contents().find('#related_videos').children().prependTo('#related_videos');
            iframe.remove();

            animateWatchPageLeft();
            animateRelatedVideos();
            cleanVidPage();
            inlineVids(related);
            inlineVids(more);
          });
        });
      });
    }
    
  };
  inlineVids(related);
  inlineVids(more);
});