// ==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 4.1.1
// @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() {
_.delay(function() {
$('div.advertisement').remove();
$('a.clearfix').remove();
$('li.pull-right').remove();
$('h2.h1').remove();
$('section.overviewPage>div:nth-child(5)').remove();
$('body > div > div.container > div > div').remove();
$('#mainSection > a').remove();
},500);
let selectors = [
'#mainSection > section > div > ul > li',
'#tabVideos > ul > li',
'#mainSection > ul > li',
'#mainSection > section > div.mainContent > ul > li',
'#mainSection > section > div > div > ul > li',
'section.row>div>div>ul>li'
];
const handleSelector = function(selector) {
$(selector).each(function() {
if ($(this).find('article > a:nth-child(1) > h3').text().trim().indexOf($(this).find('article > a.userLink.ellipsis').text().trim().split('by ')[1]) !== -1) {
$(this).remove();
} else {
if ($(this).find('article > a:nth-child(1) > h3').text().trim().indexOf('*****') !== -1) {
let titleBegin = $(this).find('article > a:nth-child(1) > h3').text().trim().split('*****')[0];
if (titleBegin === $(this).find('article > a.userLink.ellipsis').text().trim().split('by ')[1].substring(0, titleBegin.length)) {
$(this).remove();
}
}
}
if ($(this).find('article > a.userLink.ellipsis').text().includes('xtube_sponsor')) {
$(this).remove();
}
if ($(this).find('article > a > div > span.metaInfo > span').text().includes('Premium')
|| $(this).find('article > a.titleRemover.js-pop > div > span.metaInfo > span').text().includes('Preview')) {
$(this).remove();
}
if ($(this).find('article>a>span>span').text() === 'Premium' || $(this).find('article>a>div>span>span').text() === 'Premium') {
$(this).remove();
}
if ($(this).find('article>dl>dd>a').text() === 'xtube_sponsor') {
$(this).remove();
}
if ($(this).find('article>a>span>span').text() === 'Premium') {
$(this).remove();
}
let duration = $(this).find('article > a.titleRemover.js-pop > div > span.duration');
if (duration && duration.text().indexOf('0:') > -1) {
$(this).remove();
}
});
};
// v2 - Remove videos that have similar title and author strings
for (let i = selectors.length - 1; i >= 0; i--) {
if ($(selectors[i]).length > 0) {
try {
handleSelector(selectors[i]);
} catch (e) {console.log(e)}
}
}
$('#mainSection > div > div > section.cntPanel > article.box.contentInfo.hasButtonFooter').insertAfter('#mainSection > div > div > section.cntPanel > div.playerWrapper.videoWrapper');
$('body > div > div.container > div').remove();
let cleanVidPage = function() {
$('#mainSection > div > aside > div.cntPanel').remove();
$('#mainSection > div > div > section.cntPanel > div.onderSellamPlayer').remove();
let relatedVideos = null;
$('div#related_videos>div').each(function() {
relatedVideos = $(this).text().split(' ');
for (let 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();
}
});
// Remove footer ad.
$('#mainSection > div > div > div.onderSellamPlayer').remove();
// Remove "Ads by Traffic Junky"
$('#mainSection > div > div > div.expandStage > div.playerWrapper > div > div > div.header').remove();
$('body.desktopView.hasFooterAd .mainSection').css({paddingBottom: '0px'});
$('#xtubePlayer > div:nth-child(1)').remove();
$('#playerWrapper > div > p').remove();
$('#playerWrapper > div > a').unwrap();
};
cleanVidPage();
let animateThumbnails = function(selector) {
let content = _.isString(selector) ? $(selector) : selector;
if (content.length > 0) {
content.each(function(i, el) {
let originalSrc = $(el).attr('src');
let setAnimations = () => {
try {
let clone = $(el).clone();
clone.insertBefore($(el));
$(el).hide();
let animation = [];
let images;
let _src = $(this).attr('src');
let src = _src.split('/');
let isSearch = _src.indexOf('0011') !== -1;
if (_.last(src).length <= 6 || isSearch) {
let imgSrc;
if (isSearch) {
images = ['00.jpg', '01.jpg', '02.jpg', '03.jpg', '04.jpg', '05.jpg', '06.jpg', '07.jpg', '08.jpg', '09.jpg', '10.jpg', '11.jpg', '12.jpg', '13.jpg', '14.jpg'];
imgSrc = _src.split('0011')[0] + '00';
} else {
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'];
let src3 = _.without(src, _.last(src));
imgSrc = src3.join('/') + '/';
}
for (let z = 0; z < images.length; z++) {
animation.push(imgSrc + images[z]);
}
let n = -1;
let animate = function() {
clone.attr({
src: animation[++n]
});
if (n === 14) {
n = -1;
}
setTimeout(animate, 500);
};
animate();
}
} catch (e) {console.log(e)}
};
if (selector === '#tabMorefromthisuser > ul > li > article > a > div > div > img') {
$(el).parent().on('mouseenter', function(e) {
setAnimations();
});
} else {
if (originalSrc.indexOf('placehold') === -1) {
setAnimations();
} else {
el.onload = function() {
setAnimations();
};
}
}
});
}
};
// Animate thumbnails
$('#relatedVideoCarousel > footer').on('click', function() {
animateThumbnails('#relatedVideoCarousel > ul > li > ul > li > article > a > div > div > img');
});
_.delay(function() {
let thumbSelectors = [
'#mainSection > section > div > ul > li > article > a > div > div > img',
'#mainSection > ul > li > article > a > div > div > img',
'#tabVideos > ul > li > article > a > div > div > img',
'#mainSection > section > div > ul > li > article > a > div > div > img',
'div.mainContent>ul>li>article>a>div>div>img',
'[id*="vid_id_"]',
'[id*="2_frame"]> a > img',
'#tabMorefromthisuser > ul > li > article > a > div > div > img',
'#mainSection > div > div > div > ul > li > article > a > div > div > img',
'#contentVideos > div > div > ul > li > article > a > div > div.imageWrapper.video > img',
'#tabVideos > div > ul > li > article > a > div > div.imageWrapper.video > img',
'#contentActivities > div > div > ul > li > article > a > img',
'#relatedVideoCarousel > ul > li.item.active > ul > li > article > a > div > div > img'
];
for (let i = 0; i < thumbSelectors.length; i++) {
if ($(thumbSelectors[i]).length > 0) {
animateThumbnails(thumbSelectors[i]);
}
}
// Order each page by best score
let __videos = [];
let sortedByTopRated = $('#mainSection > div.contentFilterNavigation.standAlone > div > nav > ul > li:nth-child(3) > a').hasClass('active');
let orderByScore = function(selector1, selector2) {
$(selector1).each(function(i, el) {
let views = parseInt($(el).find('article > a:nth-child(1) > div > span.metaInfo > span').text().trim().split('%')[0]);
let score = parseInt($(el).find('article > a:nth-child(2) > div > span.metaInfo > span').text().trim().split('%')[0]);
if (isNaN(views)) {
views = parseInt($(el).find('article > div > div.metaInfoRight > span.viewCounter').text().trim().split('%')[0]);
}
if (isNaN(score)) {
score = parseInt($(el).find('article > div > div.metaInfoRight > span.voting.score.like').text().trim().split('%')[0]);
}
if (sortedByTopRated) {
score = views;
}
__videos.push({
score: isNaN(score) ? 0 : score,
el: el
});
$(el).remove();
});
__videos = _.chain(__videos).sortBy('score').uniq().value().reverse();
$(selector2).each(function(el) {
$(el).remove();
});
_.each(__videos, function(vid) {
$(selector2).eq(0).append($(vid.el));
});
};
let scoreArchiveSelectors = [
['#mainSection > section > div > ul > li', '#mainSection > section > div > ul'],
['#mainSection > section > div.mainContent > ul > li', '#mainSection > section > div.mainContent > ul'],
['#mainSection > section > div > div > ul > li', '#mainSection > section > div > div > ul'],
['#tabVideos > div > ul > li', '#tabVideos > div > ul'],
['#tabVideos > ul > li', '#tabVideos > ul'],
['#mainSection > ul > li', '#mainSection > ul']
];
for (let z = scoreArchiveSelectors.length - 1; z >= 0; z--) {
if ($(scoreArchiveSelectors[z][0]).length > 0) {
orderByScore(scoreArchiveSelectors[z][0], scoreArchiveSelectors[z][1]);
}
}
}, 0);
});