Greasy Fork

Greasy Fork is available in English.

Unbreak Snapchat web. Disable focus tracking and screenshot prevention

This userscript improves the Snapchat web experience by disabling screenshot prevention features which don't prevent screenshots but do actively harm the usability.

当前为 2023-06-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Unbreak Snapchat web. Disable focus tracking and screenshot prevention
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  This userscript improves the Snapchat web experience by disabling screenshot prevention features which don't prevent screenshots but do actively harm the usability.
// @author       @varenc
// @match        https://web.snapchat.com/*
// @icon         http://snapchat.com/favicon.ico
// @license MIT
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function __unblockControlKeyEvents() {
        const modifyKeys = ["Control", "Meta", "Alt","Shift"];
        
        // snapchat tries to disable console.log.. how mean. So we copy the real Console object from a new iframe
        const iframe = document.createElement("iframe");
        iframe.style.display = "none";
        document.body.appendChild(iframe);
        const nativeConsole = iframe.contentWindow.console;
        window.console=nativeConsole;
        for (var i = 0; i < arguments.length; i++) {
            var event_type = arguments[i];
            document.addEventListener(
                arguments[i],
                function (e) {
                    // console.log(`${event_type}[${i}]=`, e.key);
                    if (modifyKeys.includes(e.key)) {
                        e.preventDefault();
                        e.stopPropagation();
                        // e.stopImmediatePropagation();
                        console.log(`'${event_type}' event for '${e.key}' received and prevented:`, e);
                        e.stopImmediatePropagation();
                    }
                },
                true
            );
        }
    }
    __unblockControlKeyEvents("keydown", "keyup", "keypress");
    
    // Run a few extra times to ensure our event listeners take priority.
    setTimeout( () => __unblockControlKeyEvents("keydown", "keyup", "keypress"), 1000);
    setTimeout( () => __unblockControlKeyEvents("keydown", "keyup", "keypress"), 5000);
    setTimeout( () => __unblockControlKeyEvents("keydown", "keyup", "keypress"), 10000);

    document.hasFocus = function (){ return true }


})();