ExtendYouPorn

Remove ads, enlarges video, stops autoplay keeping buffering, fixes the overhaul style & block pop-ups

  1. // ==UserScript==
  2. // @author Jack_mustang
  3. // @version 5.0
  4. // @name ExtendYouPorn
  5. // @description Remove ads, enlarges video, stops autoplay keeping buffering, fixes the overhaul style & block pop-ups
  6. // @date 2017 October 3
  7. // @include *youporn.com/*
  8. // @include *youporngay.com/*
  9. // @run-at document-start
  10. // @grant none
  11. // @license Public Domain
  12. // @icon https://gmgmla.dm2301.livefilestore.com/y2pYluU8jK3EnLV1U8D92pYCC9wU5O04Il4j64Ft_pjKGpUG_I5L0fUHrsLpUB4oDCLIJdWp9Bwmr0RPMdhJhl5Bo362RwjatCFUpNjEdMosGA/EYP-logo.jpg
  13. // @namespace 14fac5d83892686b90beea51d35d1d7dbcfe49b6
  14. // ==/UserScript==
  15.  
  16. // Block popups fallback
  17. function NoOpen() { return 1; }
  18. parent.open = NoOpen;
  19. this.open = NoOpen;
  20. window.open = NoOpen;
  21. open = NoOpen;
  22. window.open = function () { return; };
  23. open = function () { return; };
  24. this.open = function () { return; };
  25. parent.open = function () { return; };
  26.  
  27. function fnull() {
  28. return null;
  29. }
  30.  
  31. // Block ads
  32. Object.defineProperty(window, "adDelivery", {
  33. get: fnull,
  34. set: fnull
  35. });
  36. Object.defineProperty(window, "tj_ads", {
  37. get: fnull,
  38. set: fnull
  39. });
  40. Object.defineProperty(window, "tj_channels", {
  41. get: fnull,
  42. set: fnull
  43. });
  44.  
  45. // stop autoplay
  46. Object.defineProperty(window, "MHP1138", {
  47. set: function (e) {
  48. if (!!e.players.videoContainer) {
  49. e.players.videoContainer.autoplay = false;
  50. e.players.videoContainer.autoPlayVideo.enabled = false;
  51. e.players.videoContainer.flashSettings.autoplay = false;
  52. }
  53. window.MHP1138a = e;
  54. },
  55. get: function () {
  56. return window.MHP1138a;
  57. }
  58. });
  59.  
  60. // YouPorn overrides this function, we need to to auto-centre
  61. window.scrollVid = window.scrollTo;
  62.  
  63. (function addStyle() {
  64. // While <head> is not loaded we keep trying
  65. if (!document.querySelector("head")) {
  66. return setTimeout(addStyle, 50);
  67. }
  68.  
  69. // We create an object and start including its content to include in DOM at the end
  70. var eypcss =
  71. // Hide ads while we can't remove them
  72. "iframe,\
  73. figure,\
  74. aside,\
  75. .ad-links-text,\
  76. .channelSideAd,\
  77. .sixteen-column.channel-header," +
  78. // Ad block message
  79. "#adblock_1," +
  80. // Change pause button
  81. "#pb_template > :not(.mhp1138_playerStateIcon)," +
  82. // Pornstars page, pornstars in one line
  83. ".nine-column .porn-star-list:last-child {\
  84. display: none !important;\
  85. }" +
  86. // vids in one line, on pornstars page
  87. ".column-flex,\
  88. div.eight-column:not(.title-select),\
  89. div.eight-column .row,\
  90. .pornstars-list .nine-column,\
  91. .pornstars-list .nine-column .row {\
  92. width: 100% !important;\
  93. }";
  94.  
  95. // Inject created CSS
  96. var eypnode = document.createElement("style");
  97. eypnode.type = "text/css";
  98. eypnode.id = "EYP-style";
  99. eypnode.appendChild(document.createTextNode(eypcss));
  100. document.head.appendChild(eypnode);
  101. }());
  102.  
  103. (function ExtendYouPorn(){
  104. function videoStuff() {
  105. // Scroll video to middle of page
  106. function scrollthere() {
  107. var player = document.getElementById('videoContainer');
  108. var vh = player.offsetHeight;
  109. var vd = ((document.querySelector("#network-bar").offsetHeight > 0) ? 0 : 25) + ((player.parentNode.offsetTop == 0)? ((document.querySelector('#studioCanvas'))? document.querySelector('.grid_8.alpha').offsetTop : document.querySelector('.watchWrapper').offsetTop+document.querySelector('#videoCanvas').offsetTop ) : player.parentNode.offsetTop);
  110. var fh = window.innerHeight;
  111. sc = vd - ((fh - vh) / 2);
  112. scrollVid(0, sc);
  113. // console.info("** ExtendYouPorn **\ntop: " + vd + ", height: " + vh + ", scrolled: " + sc + ", window: " + fh);
  114. }
  115. // Inject this function to page
  116. var script = document.createElement("script");
  117. script.setAttribute("type", "text/javascript");
  118. script.innerHTML = scrollthere.toString();
  119. script.id = "EYP-scrollVid";
  120. document.body.appendChild(script);
  121. scrollthere();
  122.  
  123. // Keyboard Shortcut for centring
  124. window.addEventListener('keyup', function (e) {
  125. if (e.ctrlKey && e.altKey && (e.code === "KeyC" || (e.code === undefined && e.keyCode === 67))) {
  126. scrollthere();
  127. }
  128. }, false);
  129.  
  130. // Include button in right corner to center video on screen
  131. var node = document.createElement("div");
  132. node.setAttribute("style","position: fixed;" +
  133. "bottom: 0;" +
  134. "right: 0;" +
  135. "cursor: pointer;" +
  136. "color: #fff;" +
  137. "background: #ec567c;" +
  138. "border-top-left-radius: 3px;" +
  139. "text-align: center;" +
  140. "font-size: 12px;" +
  141. "padding: 7px;" +
  142. "z-index: 999999;");
  143. node.setAttribute("onclick", "scrollthere();");
  144. node.setAttribute("title", "Use the keyboard shortcut Ctrl+Alt+C (For other keyboard layouts use the key where C should be on the QWERTY layout)");
  145. node.innerHTML = "Centre";
  146. node.id = "EYP-scroll";
  147. document.body.appendChild(node);
  148. }
  149.  
  150. var observer = new MutationObserver(function (changes) {
  151. changes.forEach(function (chg) {
  152. if (!!chg.target.className) {
  153. // remove ad spaces
  154. if (!!chg.target.className.match(/responsiveIframe/)) {
  155. var node = chg.target.parentNode;
  156. if (node.parentNode.children.length === 1 && !node.parentNode.className.match(/column/)) {
  157. node = node.parentNode.parentNode;
  158. }
  159. node.parentNode.removeChild(node);
  160. return;
  161. }
  162. // wide player
  163. if (!!chg.target.className.match(/playWrapper/)) {
  164. chg.target.className = "playWrapper sixteen-column";
  165. return;
  166. }
  167. // update wide player button
  168. if (!!chg.target.className.match(/mhp1138_front/)) {
  169. chg.target.childNodes.forEach(function (node) {
  170. if (!!node.className.match(/mhp1138_cinema/)) {
  171. node.className = "mhp1138_cinema mhp1138_cinemaState";
  172. return;
  173. }
  174. });
  175. return;
  176. }
  177. // centre video
  178. if (chg.target.id === "videoContainer") {
  179. chg.addedNodes.forEach(function (element) {
  180. if (!!element && element.id === "pb_template") {
  181. console.log(element);
  182. var node = document.createElement("div");
  183. node.className = "mhp1138_playerStateIcon";
  184. node.setAttribute("style", "opacity: 1");
  185. node.innerHTML =
  186. "<div class='mhp1138_play' style='display: block'>" +
  187. " <div class='mhp1138_icon mhp1138_icon-play'></div>" +
  188. "</div>" +
  189. "<div class='mhp1138_background'></div>";
  190. element.appendChild(node);
  191.  
  192. videoStuff();
  193. return;
  194. }
  195. });
  196. }
  197. return;
  198. }
  199. });
  200. });
  201.  
  202. observer.observe(document, {childList: true, subtree: true});
  203. }());