CoCoClick

CoCo点击方式添加控件!

目前為 2023-08-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

/*
 * ============================================================================== *
 ******************************* CoCoClick v1.0.0 *******************************
 ****************** Copyright (C) 2023 xiaohong2022 *****************
 * ============================================================================== *
*/

// ==UserScript==
// @name         CoCoClick
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  CoCo点击方式添加控件!
// @author       小宏XeLa
// @match        *://coco.codemao.cn/editor/*
// @icon         https://coco.codemao.cn/favicon.ico
// @grant        GM_addStyle
// @license      GPL-3.0
// @run-at       document-start
// ==/UserScript==


(function() {
    'use strict';
    var play = {setData(n,v){this[n]=v},getData(n){return this[n]}}
    setInterval(() => {
        document.querySelectorAll(`*[class*="WidgetList_widgetItem"]`).forEach(e=>{
            if(e.cococlick)return;
            e.cococlick=true;
            e.draggable=false;
            e.style.cursor="pointer";
            e.addEventListener("click",function(){
                var sen = document.querySelector(`*[class*="PreviewArea_main"]`);
                var x = sen.offsetLeft+sen.offsetWidth/2;
                var y = sen.offsetTop+sen.offsetHeight/2;
                var keys = Object.keys(e);
                var key = keys.find(e=>e.startsWith("__reactEventHandlers"));
                e[key].onDragStart({target:e,dataTransfer:play,persist(){return true},clientX:x,clientY:y,x:x+100,y})
                var stage = document.querySelector(`*[class*="PreviewArea_stage"]`);
                var keys2 = Object.keys(stage);
                var key2 = keys2.find(e=>e.startsWith("__reactEventHandlers"));
                stage[key2].onDragOver({preventDefault(){}})
                stage[key2].onDrop({dataTransfer:play,persist(){return true},clientX:x+142,clientY:y-3,x:x+100,y})
                if(e.dataset.widgetType=="BRUSH_WIDGET" || e.dataset.widgetType=="ACTOR_WIDGET"){
                    document.querySelectorAll(`*[data-widget-type="CANVAS_WIDGET"][id*="CANVAS_WIDGET"]`).forEach((en,index,array)=>{
                        var keys3 = Object.keys(en);
                        var key3 = keys3.find(e=>e.startsWith("__reactEventHandlers"));
                        function click(ew){
                            en[key3].onDragEnter({dataTransfer:play,persist(){return true},stopPropagation(){return true}});
                            stage[key2].onDragOver({preventDefault(){}})
                            en[key3].onDrop({dataTransfer:play,persist(){return true},stopPropagation(){return true},clientX:ew.clientX,clientY:ew.clientY,x:ew.x,y:ew.y});
                            stage[key2].onDrop({dataTransfer:play,persist(){return true}})
                            array.forEach(e=>e.removeEventListener("click",e.cococlickfunc,false))
                            e[key].onDragEnd({})
                        }
                        en.cococlickfunc = click;
                        en.addEventListener("click",click,false);
                    })
                }else{
                    e[key].onDragEnd()
                }
            })
        })
    }, 100);
    GM_addStyle(`[class*=WidgetList_widgetItem]:before{top:-16px;padding:3px 7px;width:auto;border-radius:5px;background:#fff;box-shadow:1px 1px 10px rgba(0,0,0,.33);content:"点击导入";transform:translateX(-50%)}[class*=WidgetList_widgetItem]:after,[class*=WidgetList_widgetItem]:before{position:absolute;left:50%;z-index:1e+27;color:#000;font-size:12px;opacity:0;transition:.1s}[class*=WidgetList_widgetItem]:after{top:5px;border-color:transparent transparent #fff;border-style:solid;border-width:0 5px 8px;content:"";transform:translateX(-50%) rotate(180deg)}[class*=WidgetList_widgetItem]{position:relative;z-index:1e+27}[class*=WidgetList_widgetItem]:hover:before{top:-28px;opacity:1}[class*=WidgetList_widgetItem]:hover:after{top:-6px;opacity:1}[class*=WidgetList_widgetItem]:hover{box-shadow:none!important;-webkit-transform:none!important;transform:none!important}`)
})();