-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMDbPlay.user.js
95 lines (82 loc) · 2.79 KB
/
IMDbPlay.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ==UserScript==
// @name IMDbPlay
// @namespace https://avramovic.info/
// @version 1.0.0
// @description Play movies directly from IMDb (using VidSrc)
// @author Nemanja Avramovic
// @match https://www.imdb.com/title/tt*
// @icon https://www.google.com/s2/favicons?sz=64&domain=imdb.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const observer = new MutationObserver(() => {
const pageTitle = document.querySelector("h1");
if (pageTitle && !pageTitle.querySelector('.play-icon')) {
const playIcon = document.createElement("span");
playIcon.className = "play-icon"; // Add a class to avoid duplicates
playIcon.textContent = " ▶️";
playIcon.style.cursor = "pointer";
playIcon.title = "Click to play in an overlay, ctrl+click (cmd+click on Mac) to open in a new tab.";
playIcon.addEventListener("click", (e) => {
const pathSegments = window.location.pathname.split('/').filter(segment => segment);
let imdb_id = pathSegments[1];
let media_type = document.querySelector('meta[property="og:type"]')?.content;
let base_url = 'https://proxy.garageband.rocks/embed';
let video_url = base_url + '/movie/' + imdb_id;
if (media_type === 'video.tv_show') {
video_url = base_url + '/tv/' + imdb_id;
}
if (e.ctrlKey || e.metaKey) {
window.open(video_url);
} else {
createLightbox(video_url);
}
});
pageTitle.appendChild(playIcon);
}
});
observer.observe(document.body, {childList: true, subtree: true});
function createLightbox(iframeSrc) {
// Create lightbox container
const lightbox = document.createElement('div');
Object.assign(lightbox.style, {
position: 'fixed',
top: '0',
left: '0',
width: '100vw',
height: '100vh',
backgroundColor: 'rgba(0, 0, 0, 0.8)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
zIndex: '9999',
});
// Create iframe
const iframe = document.createElement('iframe');
Object.assign(iframe.style, {
width: '90%',
height: '90%',
border: 'none',
borderRadius: '8px',
});
iframe.allowFullscreen = true;
iframe.src = iframeSrc;
// Append iframe to lightbox
lightbox.appendChild(iframe);
// Close lightbox when clicking outside iframe
lightbox.addEventListener('click', (event) => {
if (event.target === lightbox) {
lightbox.remove();
}
});
// Close lightbox when ESC is pressed
document.addEventListener('keyup', function (event) {
if (event.key === "Escape") {
lightbox.remove();
}
});
// Add lightbox to the body
document.body.appendChild(lightbox);
}
})();