view cached snaps

fuck you snapchat privacy!

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

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