Snapchat Unbreaker

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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; }

})();