22// @name Improve Adult Experience
33// @description Skip intros, set better default quality/duration filters, make unwanted video previews transparent, workaround load failures, make input more consistent across the websites. Supported websites: pornhub.com, xvideos.com, anysex.com, spankbang.com, porntrex.com, txxx.com, xnxx.com, xhamster.com, vxxx.com
44// @icon https://external-content.duckduckgo.com/ip3/pornhub.com.ico
5- // @version 0.42
5+ // @version 0.43
66// @downloadURL https://userscripts.codonaft.com/improve-adult-experience.user.js
77// ==/UserScript==
88
@@ -33,10 +33,12 @@ const INITIALIZED = '__initialized';
3333let unmuted = false ;
3434let pageIsHidden = true ;
3535
36+ const loc = window . location ;
37+
3638let redirectHref ;
3739const redirect = ( href , force ) => {
3840 if ( force ) {
39- window . location . href = href ;
41+ loc . href = href ;
4042 return ;
4143 }
4244
@@ -46,9 +48,9 @@ const redirect = (href, force) => {
4648 redirect ( redirectHref , true ) ;
4749 }
4850} ;
49- const refresh = force => redirect ( window . location , force ) ;
51+ const refresh = force => redirect ( loc , force ) ;
5052
51- const origin = window . location . origin ;
53+ const origin = loc . origin ;
5254const validLink = node => node ?. tagName === 'A' && node ?. href ?. startsWith ( origin ) ;
5355
5456const err = ( e , node ) => {
@@ -62,19 +64,6 @@ const pickRandom = xs => xs[random(0, xs.length - 1)];
6264
6365const timeToSeconds = time => ( time || '' ) . trim ( ) . split ( ':' ) . map ( parseFloat ) . reduceRight ( ( total , value , index , parts ) => total + value * 60 ** ( parts . length - 1 - index ) , 0 ) ;
6466
65- const getTopNode = ( document , node , x , y ) => {
66- if ( ! node ) return ;
67- try {
68- const rect = node . getBoundingClientRect ( ) ;
69- const clientX = rect . x + rect . width * x ;
70- const clientY = rect . y + rect . height * y ;
71- const target = document . elementFromPoint ( clientX , clientY ) || node ;
72- return { target, clientX, clientY } ;
73- } catch ( e ) {
74- err ( e , node ) ;
75- }
76- } ;
77-
7867const focus = ( node , scrollTo ) => {
7968 if ( ! node ) return ;
8069 if ( ! node . hasAttribute ( 'tabindex' ) ) {
@@ -91,7 +80,6 @@ const focus = (node, scrollTo) => {
9180
9281const simulateMouse = ( document , node , events = [ 'mouseenter' , 'mouseover' , 'mousemove' , 'mousedown' , 'mouseup' , 'click' ] ) => {
9382 if ( ! node ) return ;
94- if ( events . length === 0 ) return ;
9583
9684 console . log ( 'simulateMouse' , node , events ) ;
9785 try {
@@ -103,6 +91,19 @@ const simulateMouse = (document, node, events = ['mouseenter', 'mouseover', 'mou
10391 }
10492} ;
10593
94+ const getTopNode = ( document , node , x , y ) => {
95+ if ( ! node ) return ;
96+ try {
97+ const rect = node . getBoundingClientRect ( ) ;
98+ const clientX = rect . x + rect . width * x ;
99+ const clientY = rect . y + rect . height * y ;
100+ const target = document . elementFromPoint ( clientX , clientY ) || node ;
101+ return { target, clientX, clientY } ;
102+ } catch ( e ) {
103+ err ( e , node ) ;
104+ }
105+ } ;
106+
106107const updateUrl = ( node , href ) => {
107108 node . href = href ;
108109 node . addEventListener ( 'click' , _ => {
@@ -283,9 +284,9 @@ const init = (args = {}) => {
283284 togglePlay ( video ) ;
284285 } ;
285286
286- let lastHref = window . location . href ;
287+ let lastHref = loc . href ;
287288 subscribeOnChanges ( body , nodeChangeSelector , ( node , _observer ) => {
288- const newHref = window . location . href ;
289+ const newHref = loc . href ;
289290 if ( newHref !== lastHref ) {
290291 console . log ( 'new page' , newHref ) ;
291292 lastHref = newHref ;
@@ -336,7 +337,7 @@ const init = (args = {}) => {
336337 return true ;
337338 }
338339
339- const url = window . location ;
340+ const url = loc ;
340341 const videoPage = url . pathname !== '/' && ( ! isVideoUrl || isVideoUrl ( url . href ) ) ;
341342
342343 try {
@@ -484,7 +485,7 @@ const init = (args = {}) => {
484485} ;
485486
486487// TODO: consider redtube.com, tnaflix.com, hdzog.tube, pornxp.com, рус-порно.tv, xgroovy.com, pmvhaven.com, pornhits.com, manysex.com, inporn.com, hqporner.com, bingato.com, taboodude.com, mat6tube.com, hypnotube.com, incestporno.vip, tube8.com, drtuber.com
487- const shortDomain = window . location . hostname . replace ( / ^ w w w \. / , ' ') ;
488+ const shortDomain = loc . hostname . split ( '.' ) . slice ( - 2 ) . join ( '. ') ;
488489if ( IGNORE_HOSTS . includes ( shortDomain ) ) {
489490 console . log ( shortDomain , 'is a part of ignore list' ) ;
490491 return ;
@@ -547,7 +548,7 @@ if (IGNORE_HOSTS.includes(shortDomain)) {
547548 const videoSelector = 'video.mgp_videoElement:not(.gifVideo)' ;
548549 const durationSelector = 'var.duration, span.duration' ;
549550
550- const url = new URL ( window . location . href ) ;
551+ const url = new URL ( loc . href ) ;
551552 const params = url . searchParams ;
552553 const p = url . pathname ;
553554
0 commit comments