|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Improve Adult Experience |
3 | 3 | // @description Skip intros, set best quality and duration filters by default, make unrelated video previews transparent |
4 | | -// @version 0.3 |
| 4 | +// @version 0.5 |
5 | 5 | // @downloadURL https://userscripts.codonaft.com/improve-adult-experience.js |
6 | 6 | // @exclude-match https://spankbang.com/*/video/* |
7 | 7 | // @match https://spankbang.com/* |
|
15 | 15 | // @match https://xhamster.com/search/* |
16 | 16 | // ==/UserScript== |
17 | 17 |
|
18 | | -(() => { |
| 18 | +(_ => { |
19 | 19 | 'use strict'; |
20 | 20 |
|
21 | 21 | if (performance.getEntriesByType('navigation')[0]?.responseStatus !== 200) return; |
|
26 | 26 | const p = url.pathname; |
27 | 27 | let newUrl; |
28 | 28 |
|
29 | | - const random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min; |
| 29 | + const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min); |
30 | 30 |
|
31 | 31 | const timeToSeconds = time => (time || '').split(':').map(Number).reduceRight((total, value, index, parts) => total + value * 60 ** (parts.length - 1 - index), 0); |
32 | 32 |
|
33 | | - const pornhub = () => { |
| 33 | + const simulateClick = (document, node) => { |
| 34 | + console.log('simulateClick'); |
| 35 | + const rect = node.getBoundingClientRect(); |
| 36 | + const clientX = rect.x + rect.width / 2; |
| 37 | + const clientY = rect.y + rect.height / 2; |
| 38 | + const target = document.elementFromPoint(clientX, clientY); |
| 39 | + ['mouseover', 'mousemove', 'mousedown', 'mouseup', 'click'] |
| 40 | + .forEach(i => target.dispatchEvent(new MouseEvent(i, { clientX, clientY, bubbles: true }))) |
| 41 | + }; |
| 42 | + |
| 43 | + const pornhub = _ => { |
34 | 44 | // TODO: never redirect, just update the URLs |
35 | 45 |
|
36 | 46 | const processEmbedded = document => { |
37 | 47 | const style = document.createElement('style'); |
38 | 48 | style.innerHTML = ` |
39 | | - div.mgp_eventCatcher { display: none !important; } |
40 | 49 | div.mgp_topBar { display: none !important; } |
41 | 50 | div.mgp_thumbnailsGrid { display: none !important; } |
42 | 51 | img.mgp_pornhub { display: none !important; } |
43 | 52 | `; |
44 | 53 | document.body.appendChild(style); |
| 54 | + |
45 | 55 | const video = document.body.querySelector('video'); |
46 | | - video?.addEventListener('loadedmetadata', _ => video.currentTime = random(video.duration / 4, video.duration / 3)); |
| 56 | + if (!video) return; |
| 57 | + |
| 58 | + video.addEventListener('loadstart', _ => simulateClick(document, document.querySelector('div.mgp_playIcon'))); |
| 59 | + video.addEventListener('loadedmetadata', _ => video.currentTime = random(video.duration / 4, video.duration / 3)); |
| 60 | + document.querySelector('div.mgp_gridMenu')?.addEventListener('click', _ => setTimeout(_ => { |
| 61 | + if (video.paused) { |
| 62 | + console.log('paused on grid menu'); |
| 63 | + const button = document.querySelector('div.mgp_playIcon'); |
| 64 | + simulateClick(document, button); |
| 65 | + setTimeout(_ => { |
| 66 | + if (video.paused) { |
| 67 | + console.log('still paused'); |
| 68 | + simulateClick(document, button); |
| 69 | + } |
| 70 | + }, 500); |
| 71 | + } |
| 72 | + }, 100)); |
| 73 | + |
| 74 | + video.load(); |
47 | 75 | }; |
48 | 76 |
|
49 | 77 | const style = document.createElement('style'); |
50 | 78 | style.innerHTML = ` |
51 | | - div.unrelatedcontent { opacity: 10%; } |
52 | | - div.unrelatedcontent:hover { opacity: 40%; } |
| 79 | + div.boringcontent { opacity: 10%; } |
| 80 | + div.boringcontent:hover { opacity: 40%; } |
53 | 81 | `; |
54 | | - document.querySelector('div#main-container')?.appendChild(style); |
| 82 | + document.body.appendChild(style); |
55 | 83 |
|
56 | 84 | [...document.body.querySelectorAll('var.duration')].forEach(i => { |
57 | 85 | const duration = timeToSeconds(i.innerText); |
58 | | - const t = random(Math.floor(duration / 4), Math.floor(duration / 3)); |
| 86 | + const t = random(duration / 4, duration / 3); |
59 | 87 | const link = i.closest('a'); |
60 | 88 | if (link) { |
61 | 89 | link.href += `&t=${t}`; |
62 | 90 | } |
63 | 91 |
|
64 | 92 | const div = i.closest('a').closest('div.phimage')?.parentNode; |
65 | | - if (duration < 20 * 60) { // TODO: check quality |
66 | | - div?.classList.add('unrelatedcontent'); |
| 93 | + if (duration < 20 * 60) { // TODO: check quality and non-free-premiumness |
| 94 | + div?.classList.add('boringcontent'); |
67 | 95 | } |
68 | 96 | }); |
69 | 97 |
|
70 | 98 | if (p.startsWith('/embed/')) { |
71 | | - // happens for both iframed and redirected embedded player here |
| 99 | + // this branch gets selected for both iframed and redirected embedded player |
72 | 100 | console.log('processing embed'); |
73 | 101 | processEmbedded(document); // document is a part of iframe here |
74 | 102 | } else if (p === '/view_video.php') { |
75 | 103 | const durationFromNormalPlayer = timeToSeconds(document.body.querySelector('span.mgp_total')?.innerText); |
76 | 104 | if (durationFromNormalPlayer) { |
77 | 105 | if (!params.has('t') || Number(params.get('t')) >= durationFromNormalPlayer) { |
78 | 106 | window.stop(); |
79 | | - params.set('t', random(Math.floor(durationFromNormalPlayer / 4), Math.floor(durationFromNormalPlayer / 3))); |
| 107 | + params.set('t', random(durationFromNormalPlayer / 4, durationFromNormalPlayer / 3)); |
80 | 108 | window.location.replace(url.toString()); |
81 | 109 | } |
82 | 110 | } else { |
|
85 | 113 | const container = document.body.querySelector('div.playerFlvContainer'); |
86 | 114 | if (container) { |
87 | 115 | const iframe = document.createElement('iframe'); |
88 | | - /*iframe.onload = () => { |
| 116 | + /*iframe.onload = _ => { |
89 | 117 | console.log('iframe onload'); |
90 | 118 | processEmbedded(iframe.contentWindow.document); |
91 | 119 | };*/ |
|
110 | 138 | } |
111 | 139 | }; |
112 | 140 |
|
113 | | - const xvideos = () => { |
| 141 | + const xvideos = _ => { |
114 | 142 | // TODO: never redirect, just update the URLs |
115 | 143 |
|
116 | 144 | if (p === '/' && params.has('k') && !params.has('quality')) { |
|
127 | 155 | } |
128 | 156 | }; |
129 | 157 |
|
130 | | - const spankbang = () => { |
| 158 | + const spankbang = _ => { |
131 | 159 | // TODO: never redirect, just update the URLs |
132 | 160 |
|
133 | 161 | if (!p.endsWith('/tags') && !p.includes('/playlist/') && !(params.has('q') && params.has('d'))) { |
|
140 | 168 | } |
141 | 169 | }; |
142 | 170 |
|
143 | | - const porntrex = () => { |
| 171 | + const porntrex = _ => { |
144 | 172 | const expectedPage = (page, href) => href.startsWith(`https://www.porntrex.com/${page}/`) && (page === 'top-rated' || href.split('/').length > 5); |
145 | 173 |
|
146 | 174 | [...document.body.querySelectorAll('a')] |
|
160 | 188 | }); |
161 | 189 | }; |
162 | 190 |
|
163 | | - const xhamster = () => { |
| 191 | + const xhamster = _ => { |
164 | 192 | // TODO: never redirect, just update the URLs |
165 | 193 |
|
166 | 194 | if (p.startsWith('/search/')) { |
|
0 commit comments