view cached snaps

fuck you snapchat privacy!

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

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 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         view cached snaps
// @version      1.0.0
// @description  fuck you snapchat privacy!
// @author       tyrox.cc
// @match        https://www.snapchat.com/web*
// @run-at       document-start
// @icon         https://www.snapchat.com/web/version/17424f89/favicon.png
// @grant        none
// @license MIT
// @namespace https://greasyfork.org/users/1514019
// ==/UserScript==

(function () {
    'use strict';

    let snapchatWebpackRequire = null;
    let snapchatStore = null;

    const loadWebpackRequire = async () => {
        if (snapchatWebpackRequire == null) {
            return new Promise((resolve) => {
                window.webpackChunk_snapchat_web_calling_app.push([
                    ['inject'],
                    {
                        inject: (a, b, require) => {
                            snapchatWebpackRequire = require;
                            resolve();
                        },
                    },
                    (require) => require('inject'),
                ]);
            });
        }
    };

    const findSelectedModuleId = (webpackRequire) => {
        for (const chunk of window.webpackChunk_snapchat_web_calling_app) {
            if (Array.isArray(chunk)) {
                const [, modules] = chunk;
                for (const moduleKey of Object.keys(modules)) {
                    const module = modules[moduleKey];
                    const moduleDeclaration = module?.toString();
                    if (moduleDeclaration != null && moduleDeclaration.includes('broadcastTypingActivity')) {
                        return moduleKey;
                    }
                }
            }
        }
        return null;
    };

    const setMessageContentType = (prevState) => {
        for (const conversation of Object.values(prevState.messaging.conversations)) {
            const messages = conversation?.messages;
            if (messages instanceof Map) {
                for (const [key, message] of messages.entries()) {
                    if (message.messageContent && message.messageContent.contentType === 1) {
                        message.messageContent.contentType = 3;
                    }
                }
            }
        }
        return prevState;
    };

    const init = async () => {
        await loadWebpackRequire();

        if (snapchatWebpackRequire != null) {
            const selectedModuleId = findSelectedModuleId(snapchatWebpackRequire);

            if (selectedModuleId != null) {
                const module = snapchatWebpackRequire(selectedModuleId);
                snapchatStore = Object.values(module).find(
                    (value) => value.getState != null && value.setState != null
                );

                if (snapchatStore) {
                    snapchatStore.setState(setMessageContentType);
                }
            }
        }
    };

    setInterval(init, 1000);
})();