Sleazy Fork is available in English.

xHamster Enhancement - XE

Adds endless scroll and increases the default player size.

  1. // ==UserScript==
  2. // @name xHamster Enhancement - XE
  3. // @locale en
  4. // @namespace farami
  5. // @version 0.1.3
  6. // @description Adds endless scroll and increases the default player size.
  7. // @author Genevera (original by farami)
  8. // @require http://code.jquery.com/jquery-latest.js
  9. // @match *://xhamster.com/*
  10. // @grant none
  11. // ==/UserScript==
  12. /* jshint -W097 */
  13. 'use strict';
  14. (function(){
  15. $.ajaxSettings.beforeSend=function(xhr){
  16. xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
  17. };
  18. })(jQuery);
  19. var xes = function() {
  20. var currentPage = 1;
  21. var totalPages = -1;
  22. var currentPageName = location.href;
  23. var endlessScrollRunning = false;
  24. var settingsMenuOpened = false;
  25.  
  26. var config = {
  27. resizePlayer: true,
  28. removeAds: true,
  29. endlessScroll: {
  30. enabled: true,
  31. triggerAtPercent: 80
  32. }
  33. };
  34.  
  35. var init = function() {
  36. if (config.resizePlayer) {
  37. adjustPlayerSize();
  38. }
  39.  
  40. if (config.removeAds) {
  41. hideElements();
  42. }
  43.  
  44. if (config.endlessScroll.enabled) {
  45. enableEndlessScroll();
  46. }
  47. };
  48.  
  49. var hideElements = function() {
  50. if (location.href.indexOf('movies') === -1) {
  51. return;
  52. }
  53.  
  54. $('.aspt,.sponsorBottom,.avdo.adVideo2,#supportAds,.avdo.fr').remove();
  55. };
  56.  
  57. var adjustPlayerSize = function() {
  58. if (getCurrentPage() !== 'movies') {
  59. return;
  60. }
  61.  
  62. $('#playerBox').width(1000);
  63. document.getElementById('playerSwf').style.height = '777px';
  64. document.getElementById('player').style.height = '777px';
  65. document.getElementById('commentBox').style.width = 'auto';
  66. $('video').height(777).width(980);
  67. $('#player').width(980);
  68. };
  69.  
  70. var enableEndlessScroll = function() {
  71. var pager = $('.pager > table > tbody > tr > td > div');
  72. // totalPages = pager.find(':nth-last-child(2)').html();
  73. if (!getCurrentPage().contains("movies") && totalPages !== undefined) {
  74. //$('.box.boxTL > .head,.box > .head.gr').append('<span style="float: right">Total Pages: ' + totalPages + '</span>');
  75. }
  76. currentPageName = pager.find('a').attr('href');
  77. if (!getCurrentPage().contains("user")) {
  78. $('.pager').remove();
  79. }
  80.  
  81. var videoList = $(".boxC.videoList.clearfix");
  82. $(".fl").children().not(".clear").addClass("no-padding").prependTo(videoList);
  83. $(".related-categories").prependTo(videoList);
  84. $(".video").not(".no-padding").addClass("no-padding");
  85. $(".fl,.boxC > .clear,.category-description,.vDate").remove();
  86.  
  87. document.addEventListener('scroll', triggerEndlessScroll);
  88. };
  89.  
  90. var triggerEndlessScroll = function() {
  91. if (getScrollPercent() >= config.endlessScroll.triggerAtPercent) {
  92. if (endlessScrollRunning) {
  93. return;
  94. }
  95.  
  96. endlessScrollRunning = true;
  97. // load next page
  98. $.get(currentPageName.replace('/'+currentPage, '/'+(currentPage + 1)), function(page) {
  99. var page;
  100.  
  101. // for some reason xhamster displays search results differently to everything else
  102. if (currentPageName.contains('search.php')) {
  103. page = $(page).find('.boxC > table > tbody > tr > td > *').not('.avdo.fr');
  104. page.appendTo('.boxC > table > tbody > tr > td');
  105. }
  106. else if (currentPageName.contains('friends')) {
  107. page = $(page).find('div .friendsList > *');
  108. page.appendTo('div .friendsList');
  109. }
  110. else {
  111. page = $(page).find('div .video');
  112. var am = $('.pager').parent();
  113. page.appendTo(am);
  114. }
  115.  
  116. $(".fl,.boxC > .clear,.category-description,.vDate").remove();
  117. $(".video").not(".no-padding").addClass("no-padding");
  118. endlessScrollRunning = false;
  119.  
  120. currentPageName = currentPageName.replace('/'+currentPage, '/'+(currentPage + 1));
  121. currentPage++;
  122. });
  123. }
  124. };
  125.  
  126. var getCurrentPage = function() {
  127. return /xhamster.com\/(\w+)/i.exec(location.href)[1];
  128. }
  129.  
  130. Element.prototype.remove = function() {
  131. this.parentElement.removeChild(this);
  132. };
  133.  
  134. NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
  135. for(var i = this.length - 1; i >= 0; i--) {
  136. if(this[i] && this[i].parentElement) {
  137. this[i].parentElement.removeChild(this[i]);
  138. }
  139. }
  140. };
  141.  
  142. String.prototype.contains = function(text) {
  143. return this.toLowerCase().indexOf(text.toLowerCase()) > -1;
  144. };
  145.  
  146. var getScrollPercent = function() {
  147. var h = document.documentElement,
  148. b = document.body,
  149. st = 'scrollTop',
  150. sh = 'scrollHeight';
  151. return h[st]||b[st] / ((h[sh]||b[sh]) - h.clientHeight) * 100;
  152. };
  153.  
  154. return { init: init, config: config };
  155. }();
  156.  
  157. $(document).ready(function() {
  158. xes.init();
  159. });