Kong Flash API Patcher

Intercepts Kongregate Flash API fetch() request to return a modified version that will function properly

Από την 08/05/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Kong Flash API Patcher
// @version      1.1
// @author       Colin969
// @description  Intercepts Kongregate Flash API fetch() request to return a modified version that will function properly
// @license      MIT
// @match        *://*.konggames.com/games/*/*/frame/*
// @match        *://www.kongregate.com/games/*/*
// @match        *://www.kongregate.com/*/games/*/*
// @match        *://www.kongregate.com/accounts/*/card_album*
// @run-at       document-start
// @grant        none
// @namespace https://greasyfork.org/users/1296974
// ==/UserScript==

(function() {
    'use strict';
    // Create JS replacement funcs
    window.flashApiSendMessage = (opcode, parameters) => {
        setTimeout(() => {
            kongregateAPI.messageConnection.sendMessage(opcode, decodeURIComponent(parameters));
        });
    };

    window.flashApiBootstrap = (swfId, apiUrl) => {
        console.log('Flash setting up from ' + swfId);
        setTimeout(() => {
            function setGameSwf(){
                if (typeof kongregateAPI !== 'undefined') {
                    // Ruffle doesn't have Play function, removed from check
                    kongregateAPI._isSwf = function(e) {
                        return e && void 0 !== e.setConnectionObject;
                    };

                    // Modified to check for ruffle-player, not just objects and embeds
                    kongregateAPI._findSwf = function(e) {
                        var t = document.getElementById(e),
                            n = this,
                            s = function(e) {
                                for (var s = 0; s < e.length; s++)
                                    if (t = e[s], n._isSwf(t)) return t
                            };
                        return this._isSwf(t) ? t : t = s(document.getElementsByName(e)) || s(document.querySelectorAll("[id='" + e + "']")) || s(document.getElementsByTagName("object")) || s(document.getElementsByTagName("embed")) || s(document.getElementsByTagName("ruffle-player"))
                    };
                    setTimeout(function(){ kongregateAPI._setGameSwf(swfId); }, 1);
                    return true;
                }
            }

            function loadKongregateApi() {
                var s = document.createElement('script');
                s.type ='text/javascript';
                s.src = apiUrl;
                if(s.addEventListener) {
                    s.addEventListener('load', setGameSwf)
                } else if(s.readyState) {
                    s.onreadystatechange = setGameSwf;
                }
                document.getElementsByTagName('head')[0].appendChild(s);
            }

            if (!setGameSwf()) {
                loadKongregateApi();
            }
            return 'pending';
        });
        return "pending";
    };

    // Replace fetch so we can capture the api
    const originalFetch = window.fetch;

    window.fetch = function(req, options) {
        let request = new URL(req instanceof Request ? req.url : req);

        if (request.href.includes("API_AS3_d43c4b859e74432475c1627346078677.swf") || request.href.includes("/flash/API_AS3.swf")) {
            request.href = "https://colin969.github.io/Kongregate-Patched-APIs/API_AS3_MODIFIED.swf";
        }

        if (request.href.includes("API_f99fa1a5a43e48224ae2c0177064456d.swf") || request.href.includes("/flash/API.swf")) {
            request.href = "https://colin969.github.io/Kongregate-Patched-APIs/API_AS2_MODIFIED.swf";
        }

        return originalFetch(request, options);
    };
})();