summaryrefslogtreecommitdiff
path: root/preload.js
blob: 622ac932dc2a9507c3911b0ab50e3d057eb3c39c (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const { ipcRenderer } = require('electron');
let trafficLightsOn = false;
let lastResized = false;
let lastSize = null;

ipcRenderer.on('resize', () => {
    lastResized = true;
})

ipcRenderer.on('resize-normal', () => {
    lastResized = false;
})

ipcRenderer.on('traffic-lights-on', () => {
    trafficLightsOn = true;
})

ipcRenderer.on('traffic-lights-off', () => {
    trafficLightsOn = false;
})

window.addEventListener("load", () => {
    let css = `
    .NavBar-container-F87RQ_ {
        -webkit-app-region: drag;
    }
    
    a.NavBarButton-button-cMcOo3.Link-link-SxPFpG.Link-link-SxPFpG.Link-default-BXtKLo {
        display: none;
    }
    
    .NavBar-buttonSeparator-racpPW {
        display: none;
    }
    
    a.pksp574._11ni0ce1e._11ni0cea._11ni0cen1[href="#!/announcements"] {
        display: none;
    }
    
    a.pksp574._11ni0ce1e._11ni0cea._11ni0cen1[href="https://support.plex.tv?utm_source=Plex%20Apps&utm_medium=Plex%20Web&utm_campaign=Plex%20Apps"] {
        display: none;
    }
    
    a.pksp574._11ni0ce1e._11ni0cea._11ni0cen1[href="https://plex.tv/downloads"] {
        display: none;
    }
    
    a.MenuItem-menuItem-C_KBbX.MenuItem-default-NAJl2g.Link-link-SxPFpG.Link-default-BXtKLo {
        display: none;
    }
    
    .FullPlayerTopControls-topControls-Fp11QH, .Player-fullPlayerContainer-wBDz23 .BottomBar-bottomBar-hnsKzI {
        backdrop-filter: blur(10px);
    }`;

    let styleSheet = document.createElement("style");
    styleSheet.innerText = css;
    document.head.appendChild(styleSheet);

    let lastShown = false;
    let knownHeight = 0;

    setInterval(() => {
        if (document.querySelector(".Player-fullPlayerContainer-wBDz23")) {
            if (lastShown === false) {
                lastShown = true;
                console.log("Play!");

                let height = Math.round(((document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoHeight * window.innerWidth) / document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoWidth));
                console.log(document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoWidth + "x" + document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoHeight);
                knownHeight = height;
                console.log(window.innerWidth + "x" + height);
                if (!lastSize) lastSize = window.innerHeight;
                lastResized = false;
                if (currentHeight > 0 && !isNaN(currentHeight)) ipcRenderer.send("resize-to-match", height);
            }

            let currentHeight = Math.round(((document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoHeight * window.innerWidth) / document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoWidth));
            if (knownHeight !== currentHeight) {
                Math.round(((document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoHeight * window.innerWidth) / document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoWidth));
                console.log(document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoWidth + "x" + document.querySelector(".HTMLMedia-mediaElement-u17S9P").videoHeight);
                console.log(window.innerWidth + "x" + currentHeight);
                if (!lastSize) lastSize = window.innerHeight;
                lastResized = false;
                if (currentHeight > 0 && !isNaN(currentHeight)) ipcRenderer.send("resize-to-match", currentHeight);
            }

            knownHeight = currentHeight;
        } else {
            console.log(lastResized, lastSize);
            if (!lastResized && lastSize && lastSize > 0 && !isNaN(lastSize)) {
                ipcRenderer.send("resize-to-match", lastSize);
                lastResized = true;
                lastSize = null;
            }
            lastShown = false;
        }
    })

    if (require('os').platform() === "darwin") {
        trafficLightsOn = true;
        setInterval(() => {
            showTrafficLights();
        });
        showTrafficLights();
    }
})

function showTrafficLights() {
     try {
         if (trafficLightsOn) {
             document.querySelector("._11ni0ce12._11ni0ce9._11ni0ce1m._11ni0ce2a._11ni0ce2i._11ni0ce2u._11ni0ce3a").style.marginLeft = "75px";
             document.querySelector("button.PlayerIconButton-playerButton-zDmEsI.IconButton-button-s4bVCh.Link-link-SxPFpG.Link-default-BXtKLo[data-testid=\"minimizePlayerButton\"]").style.marginLeft = "80px";
         } else {
             document.querySelector("._11ni0ce12._11ni0ce9._11ni0ce1m._11ni0ce2a._11ni0ce2i._11ni0ce2u._11ni0ce3a").style.marginLeft = "0px";
             document.querySelector("button.PlayerIconButton-playerButton-zDmEsI.IconButton-button-s4bVCh.Link-link-SxPFpG.Link-default-BXtKLo[data-testid=\"minimizePlayerButton\"]").style.marginLeft = "0px";
         }
     } catch (e) {}
}