CoCo 作品分享审核绕过

绕过 CoCo 作品分享的审核机制,让他人可以看到你分享的作品,请低调使用

当前为 2024-02-24 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         CoCo 作品分享审核绕过
// @namespace    https://slightning.rechen.xyz/
// @version      0.1.2
// @description  绕过 CoCo 作品分享的审核机制,让他人可以看到你分享的作品,请低调使用
// @author       SLIGHTNING
// @match        http://coco.codemao.cn/editor/*
// @match        https://coco.codemao.cn/editor/*
// @icon         https://coco.codemao.cn/favicon.ico
// @grant        none
// @license      GPL
// ==/UserScript==

(function() {
    'use strict';

    function modifyWork(work) {
        var unsafeList = work.unsafeExtensionWidgetList,
            safeList = work.extensionWidgetList
        moveUnsafeToSafe(unsafeList, safeList)
        work.globalWidgetIds = work.globalWidgetIds.map(removeUnsafe)
        mapRemoveUnsafe(work.globalWidgets)
        Object.values(work.screens).forEach(screen => {
            screen.widgetIds = screen.widgetIds.map(removeUnsafe)
            screen.invisibleWidgetIds = screen.invisibleWidgetIds.map(removeUnsafe)
            mapRemoveUnsafe(screen.widgets)
        })
        blockRemoveUnsafe(work.blockly)
    }

    function moveUnsafeToSafe(unsafeList, safeList) {
        var safeMap = {}
        safeList.forEach(safe => {
            safeMap[safe.type] = safe
        })
        var unsafe
        while (unsafe = unsafeList.shift()) {
            var sefe,
                cdnUrl = `data:text/plain;charset=UTF-8,${encodeURIComponent(unsafe.code)}//`,
                type = removeUnsafe(unsafe.type)
            if (safe = safeMap[type]) {
                safe.cdnUrl = cdnUrl
            } else {
                var safe = {
                    id: Math.floor(Math.random() * 10000) + 10000,
                    type: type,
                    cdnUrl: cdnUrl
                }
                safeList.push(safe)
            }
        }
    }

    function mapRemoveUnsafe(map) {
        Object.keys(map).forEach(function(key) {
            var widget = map[key]
            delete map[key]
            var id = removeUnsafe(key)
            map[id] = widget
            widget.id = id
            widget.type = removeUnsafe(widget.type)
        })
    }

    function blockRemoveUnsafe(screenBlock) {
        Object.values(screenBlock).forEach(screen => {
            Object.values(screen.workspaceJson.blocks).forEach(block => {
                var {fields, shadows} = block
                if (fields.WIDGET_ID) {
                    fields.WIDGET_ID = removeUnsafe(fields.WIDGET_ID)
                }
                block.mutation = block.mutation.replaceAll("widget_type=\"UNSAFE_", "widget_type=\"")
                if (shadows.PARAM_text) {
                    shadows.PARAM_text = shadows.PARAM_text.replaceAll("widget_type=\"UNSAFE_", "widget_type=\"")
                }
            })
        })
    }

    function removeUnsafe(id) {
        if (id.startsWith("UNSAFE_")) {
            return id.substring(7)
        } else {
            return id
        }
    }

    var originalFetch = fetch
    fetch = async function(input, init) {
        var response = await originalFetch(input, init)
        if (input.startsWith("https://creation.codemao.cn/716/appcraft/JSON") &&
            response.ok) {
            var responseToModify = response.clone()
            var work = await responseToModify.json()
            if (!work.blockCode) {
                modifyWork(work)
            }
            var modifiedResponse = new Response(JSON.stringify(work), {
                ...response
            })
            return modifiedResponse
        } else {
            return response
        }
    }

    async function modifyReleaseFile(file) {
        file.extensionWidgetList.push({
            id: 0,
            type: "EXTENSION_SLIGHTNING_BYPASS_AUDIT",
            cdnUrl:
                "data:text/plain;charset=UTF-8," +
                encodeURIComponent(`
                    new Function(\`(\${(async () => {
                        "use strict";
                        if (!window.SLIGHTNING_BYPASS_AUDIT_STOP) {
                            window.SLIGHTNING_BYPASS_AUDIT_STOP = true
                            var originalAlert = alert
                            alert = (message) => {
                                if (message == "作品审核中,请稍后再试") {
                                    console.log.apply(this, arguments)
                                    throw new Error("阻断 Player 检查自定义控件")
                                } else {
                                    originalAlert.apply(this, arguments)
                                }
                            }
                    
                            var iframe = document.createElement("iframe")
                            iframe.src = location.href
                            var {style} = iframe
                            style.border = "none"
                            style.position = "fixed"
                            style.left = "0px"
                            style.top = "0px"
                            style.width = "100%"
                            style.height = "100%"
                            document.body.append(iframe)
                            var {contentWindow} = iframe
                            contentWindow.SLIGHTNING_BYPASS_AUDIT_STOP = true
                    
                            var originalIncludes = contentWindow.Array.prototype.includes
                            contentWindow.Array.prototype.includes = (string) => {
                                if (string.startsWith("data:text/plain;charset=UTF-8,")) {
                                    return true
                                }
                                return originalIncludes.apply(this, arguments)
                            }
                        }
                    }).toString()})()\`)()
                    const types = {
                        type: "SLIGHTNING_BYPASS_AUDIT",
                        title: "审核绕过",
                        icon: "",
                        isInvisibleWidget: true,
                        isGlobalWidget: true,
                        properties: [],
                        methods: [],
                        events: []
                    }
                    class Widget extends InvisibleWidget {
                        constructor(props) {
                            super(props)
                        }
                    }
                    exports.types = types
                    exports.widget = Widget
                //`)
        })
        delete file.blockJsonMap
    }

    var originalSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function(data) {
        if (data instanceof FormData) {
            var fileName = data.get("fname"),
                originalFile = data.get("file")
            if (fileName == "test.json") {
                var xhr = this,
                    xhrArguments = arguments
                var reader = new FileReader()
                reader.readAsText(originalFile)
                reader.onload = async function() {
                    try {
                        var fileContent = JSON.parse(this.result)
                        await modifyReleaseFile(fileContent)
                        var blob = new Blob([JSON.stringify(fileContent)], { type: "text/plain" })
                        var file = new File([blob], originalFile.name, { type: originalFile.type })
                        data.set("file", file)
                    } catch (error) {
                        console.error(error)
                        alert(`绕过审核失败:${error.message}`)
                    }
                    originalSend.apply(xhr, xhrArguments)
                }
            } else {
                originalSend.apply(this, arguments)
            }
        } else {
            originalSend.apply(this, arguments)
        }
    }
})()