Snapchat Unbreaker

Improve the Snapchat web experience by disabling screenshot prevention features that harm usability.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Snapchat Unbreaker
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  Improve the Snapchat web experience by disabling screenshot prevention features that harm usability.
// @match        https://web.snapchat.com/*
// @match        https://www.snapchat.com/web/*
// @icon         http://snapchat.com/favicon.ico
// @license      MIT
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function unblockControlKeyEvents() {
        const events = ["keydown", "keyup", "keypress"];
        const modifyKeys = ["Control", "Meta", "Alt", "Shift"];
        for (const event_type of events) {
            document.addEventListener(
                event_type,
                function (e) {
                    if (modifyKeys.includes(e.key)) {
                        e.preventDefault();
                        e.stopPropagation();
                        console.log(`'${event_type}' event for '${e.key}' received and prevented:`, e);
                        e.stopImmediatePropagation();
                    }
                },
                true
            );
        }
    }

    function unblockEvent() {
        for (const event_type of arguments) {
            document.addEventListener(
                event_type,
                function (e) {
                    e.stopPropagation();
                    console.log(`'${event_type}' event received and prevented:`, e);
                },
                true
            );
        }
    }

    function fixConsole() {
        const iframe = document.createElement("iframe");
        iframe.style.display = "none";
        document.body.appendChild(iframe);
        const nativeConsole = iframe.contentWindow.console;
        window.console = nativeConsole;
    }

    function setupUnblocker() {
        fixConsole();
        unblockControlKeyEvents();

        // Allow right-click without losing focus
        unblockEvent("contextmenu");
    }

    console.dir("Snapchat unbreaker running!");
    setupUnblocker();
    // Run a few extra times to ensure event listeners take priority.
    setTimeout(setupUnblocker, 1000);
    setTimeout(setupUnblocker, 5000);
    setTimeout(setupUnblocker, 10000);

    // Ensure focus is always true.
    document.hasFocus = function() { return true; }

})();