PH.com

Remove ads, enlarges video, stops autoplay keeping buffering & block pop-ups from pornhub.com

  1. // ==UserScript==
  2. // @author Jack_mustang
  3. // @contributor doej
  4. // @version 1.21
  5. // @name PH.com
  6. // @description Remove ads, enlarges video, stops autoplay keeping buffering & block pop-ups from pornhub.com
  7. // @date 2016 April 08
  8. // @include *pornhub.com/*
  9. // @run-at document-start
  10. // @grant none
  11. // @license Public Domain
  12. // @icon https://gmgmla.dm2301.livefilestore.com/y2pAKJYeZAp4tG23hG68x1mRuEUQXqb1MxdLbuqVnyyuHFxC7ra5Fc-tfq6hD-r9cNnVufT3egUHaimL547xDlESrOVmQsqNSJ5gzaiSccLYzo/ExtendPornHub-logo.png
  13. // @namespace 649b97180995e878e7e91b2957ef3bbee0f840a0
  14. // ==/UserScript==
  15.  
  16. // jshint multistr: true
  17. // globals: open parent
  18.  
  19. var QUALITIES = ['240p', '480p', '720p'];
  20. var CENTER_BUTTON_STYLE = " \
  21. position: fixed; \
  22. bottom: 0; \
  23. right: 0; \
  24. cursor: pointer; \
  25. border: 1px solid #313131; \
  26. border-top-left-radius: 5px; \
  27. color: #676767; \
  28. font-weight: 700; \
  29. background: #101010; \
  30. text-align: center; \
  31. font-size: 12px; \
  32. padding: 7px 15px; \
  33. z-index: 999999; \
  34. ";
  35. var FLASH_VARS = {
  36. "autoplay" : false,
  37. "autoload" : true,
  38. "htmlPauseRoll" : false,
  39. "htmlPostRoll" : false,
  40. "video_unavailable_country" : false,
  41. };
  42.  
  43. // Block popups
  44. function yes(e){ return 1; }
  45. function blockPopups() {
  46. window.open = yes;
  47. parent.open = yes;
  48. // Pop-up killer, we trick PH to think we are old Presto Opera, this kills the pop-ups
  49. if (!window.opera)
  50. window.opera = true;
  51. }
  52.  
  53. // Autoplay, autoload, etc.
  54. function changePlayer() {
  55. if (!document.getElementById('player'))
  56. return setTimeout(changePlayer, 50);
  57. var player = document.getElementById('player'),
  58. vidId = parseInt(player.getAttribute("data-video-id")),
  59. newflashvars = document.createElement("script");
  60. newflashvars.setAttribute("type", "text/javascript");
  61. newflashvars.id = "EPH-newflashvars";
  62. newflashvars.innerHTML = '';
  63. for (var k in FLASH_VARS) {
  64. newflashvars.innerHTML += ['flashvars_',vidId,'.',k,'=',FLASH_VARS[k],';\n'].join('');
  65. }
  66. document.body.appendChild(newflashvars);
  67. }
  68.  
  69. // wait while player doesn't load
  70. function html5player() {
  71. var flash = document.querySelector("#player object"),
  72. html5 = document.querySelector("#player video");
  73. if (flash === null && html5 === null)
  74. return setTimeout(html5player, 50);
  75. document.getElementById("hd-rightColVideoPage").setAttribute("class", "wide");
  76. document.getElementById("player").setAttribute("class", "wide");
  77. var vidId = parseInt(document.getElementById('player').getAttribute("data-video-id")),
  78. playerDiv = document.getElementById("playerDiv_"+vidId);
  79. playerDiv.setAttribute("class", playerDiv.getAttribute("class") + " wide");
  80. scrollthere();
  81. }
  82.  
  83. // Scroll video to middle of page
  84. function scrollthere() {
  85. var player = document.getElementById('player'),
  86. vh = player.offsetHeight,
  87. vd = document.querySelector(".container").offsetTop +
  88. document.querySelector(".container").parentNode.offsetTop +
  89. document.querySelector(".video-wrapper").offsetTop +
  90. ((document.querySelector("#PornhubNetworkBar>.bar_body") === null) ? 25 : 0),
  91. fh = window.innerHeight,
  92. sc = vd-((fh-vh)/2);
  93. scrollTo(0, sc);
  94. console.info("** ExtendPornHub **\ntop: "+vd+", height: "+vh+", scrolled: "+sc+", window: "+fh) ;
  95. }
  96.  
  97. // Remove ads functions
  98. function removeQuery(query) {
  99. var ifr = document.querySelectorAll(query);
  100. if(ifr.length > 0)
  101. for(var i=0; i < ifr.length; i++)
  102. ifr[i].parentNode.removeChild(ifr[i]);
  103. }
  104.  
  105. function addStyle() {
  106. // While <head> is not loaded we keep trying
  107. if (!document.querySelector("head"))
  108. return setTimeout(addStyle, 50);
  109.  
  110. // We create an object and start including its content to include in DOM at the end
  111. var ephcss =
  112. // Hide ads while we can't remove them
  113. "iframe, \
  114. .home-ad-container, \
  115. .adblockWhitelisted, \
  116. .browse-ad-container, \
  117. .playlist-ad-container, \
  118. .communityAds, \
  119. .photo-ad-container, \
  120. #advertisementBox, \
  121. .ad_box, \
  122. .ad-link, \
  123. .removeAdLink, \
  124. div[class$=shareBtn], \
  125. #videoPageAds, \
  126. .sectionTitle + div:not(#categoriesStraightImages), \
  127. .edit-mode + div, \
  128. .generator-sidebar > .sectionWrapper:first-child, \
  129. .gifsWrapper > div:first-child {\
  130. display: none !important;\
  131. }" +
  132. // Videos Being Watched Right Now in one line + video ads + adBlock bar
  133. "ul.row-5-thumbs.videos-being-watched li.omega, #pb_block, .abAlertShown {\
  134. display: none !important;\
  135. }" +
  136. // Maximum full-width video
  137. "div#player {\
  138. max-width: 100vw;\
  139. max-height: 100vh;\
  140. }";
  141.  
  142. // Inject created CSS
  143. var ephnode = document.createElement("style");
  144. ephnode.type = "text/css";
  145. ephnode.id = "EPH-style";
  146. ephnode.appendChild(document.createTextNode(ephcss));
  147. document.head.appendChild(ephnode);
  148. }
  149.  
  150. function main(){
  151. // Stop popups (again)
  152. blockPopups();
  153. // Set flash vars
  154. changePlayer();
  155. // Remove iframes because they are ads
  156. removeQuery("iframe:not(#pb_iframe)");
  157. // Homepage
  158. removeQuery(".home-ad-container");
  159. removeQuery(".adblockWhitelisted");
  160. // Search
  161. removeQuery(".browse-ad-container");
  162. // Playlist
  163. removeQuery(".playlist-ad-container");
  164. // Community
  165. removeQuery(".communityAds");
  166. // Photo Gif
  167. removeQuery(".photo-ad-container");
  168. // unique Photo
  169. removeQuery("#advertisementBox");
  170. // Video
  171. removeQuery("videoPageAds");
  172.  
  173. // Stop unless we're on a video page
  174. if( ! document.getElementById('player')) {
  175. return;
  176. }
  177.  
  178. // Wide display
  179. html5player();
  180.  
  181. // Include button in right corner to center video on screen
  182. var node = document.createElement("div");
  183. node.setAttribute("style", CENTER_BUTTON_STYLE);
  184. node.onclick = scrollthere;
  185. node.innerHTML = "Center video";
  186. node.id = "EPH-scroll";
  187. document.body.appendChild(node);
  188. // Add video download when not logged
  189. if( document.body.classList[0].search("logged-in") < 0 ) {
  190. var tab = document.querySelector(".download-tab"),
  191. dwlinks = '';
  192. for (var i = 0; i < QUALITIES.length; i++) {
  193. var quality = QUALITIES[i];
  194. var quality_url = window["player_quality_" + quality];
  195. if (quality_url) {
  196. dwlinks += '<a class="downloadBtn greyButton" target="_blank" href="' + quality_url + '">';
  197. dwlinks += '<i></i>';
  198. if (quality === '720p') dwlinks += '<span>HD</span>&nbsp;';
  199. quality += '</a>';
  200. }
  201. }
  202. tab.innerHTML = dwlinks;
  203. }
  204. }
  205.  
  206. function consumeKeyDown(e) {
  207. if (e.altKey && 'C' === String.fromCharCode(e.keyCode)) {
  208. scrollthere();
  209. }
  210. }
  211.  
  212.  
  213. /*
  214. *
  215. * main
  216. */
  217.  
  218. blockPopups();
  219. addStyle();
  220. window.addEventListener('DOMContentLoaded', main, false);
  221. document.addEventListener('keydown', consumeKeyDown, false);
  222.  
  223. // vim: sw=4 noet :