Snapchat Unbreaker

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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; }

})();