Netflix Screenshot Hack

Simulates casting page. Press Alt+C to start/stop fake capture.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Netflix Screenshot Hack
// @namespace    http://netflix.com
// @version      1.0.1
// @description  Simulates casting page. Press Alt+C to start/stop fake capture.
// @author       igmn
// @match        https://www.netflix.com/*
// @license      MPL-2.0
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAAAgUlEQVRYw+3YMQ6AIAwFUM4hp3fovVxgkTt8FzcxocRqWv+fCS8BSigpBQ0yBBWj2bBi0U3foM2uICCYiYwDZQoo48AZq/HvAdoQeB7wf4p6y0XgBjDfAwJfAv4rOTJwrXYCQYDe9U2Ab1MC/3ybmjeB5m3sTCPekO2+EipENb2rHNr8w2PHFGGbAAAAAElFTkSuQmCC
// @grant        none
// ==/UserScript==

/* jshint esversion:6 */

// Press ALT+C

(function () {
    'use strict';

    if (!localStorage.getItem('firstTime')) localStorage.setItem('firstTime', 'true');

    if (localStorage.getItem('firstTime') == 'true') {
        alert(`
This script will fake a capture to fool Chromium into thinking that we are casting.
Press Alt+C after this alert, select your browser in the Window tab, and you should be able to screen record and screenshot Netflix.
Enjoy :)`);
        localStorage.setItem('firstTime', 'false');
    }

    const fakeVideo = document.createElement('video');
    let isCapturing = false;

    document.onkeydown = keydown;
    function keydown(evt = event) {
        // Alt + C (stop capturing)
        if (evt.altKey && evt.keyCode == 67 && isCapturing) {
            isCapturing = false;
            fakeVideo.srcObject.getTracks().forEach(track => track.stop())
            return;
        }

        // Alt + C (start capturing)
        if (evt.altKey && evt.keyCode == 67) {
            getDisplayMedia(screen => {
                isCapturing = true;
                console.log(isCapturing);
                fakeVideo.srcObject = screen;
            });
            return;
        }
    }

    function getDisplayMedia(success, error) {
        if (navigator.mediaDevices.getDisplayMedia) navigator.mediaDevices.getDisplayMedia().then(success).catch(error);
        else navigator.getDisplayMedia().then(success).catch(error);
    }

})();