LowCodeEngine

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         LowCodeEngine
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  try to take over the world!
// @author       You
// @match        *://*/*
// @grant        none
// @run-at       document-end
// ==/UserScript==
/* eslint-disable */

function safeGet(target, paths, defaultValue) {
  const safeGetRegex = /\[|(?:\]\[?)|\./g;
  if (typeof paths === 'string') {
    paths = paths.split(safeGetRegex).filter(p => !!p);
  }
  if (target) {
    const result = paths.some(p => {
      target = target[p];
      if (target === null || target === undefined) {
        return true;
      }
    });
    return result ? defaultValue : target;
  }
  return target;
}

const settedMap = {};
function defineProperty(name, descriptor) {
    if (window[name]) return;
    Object.defineProperty(window, name, descriptor);
}

function definePropertyWithGetter(name, path) {
    if (settedMap[name]) return;
    settedMap[name] = true;
    defineProperty(name, { get() { return safeGet(window, path); } });
}

(function() {
    'use strict';
    let tries = 0;
    const maxTries = 10;
    // if (window.RenderEngine) return;
    const iterId = setInterval(function() {
        if (tries++ >= maxTries) clearInterval(iterId);

        if (window.LeGao && window.LeGao.getContext && window.LeGao.getContext()) {
            clearInterval(iterId);
            const ctx = LeGao.getContext();
            window.$ctx = ctx;
            window.$schema = ctx.schema;
            window.$page = ctx.schema.pages && ctx.schema.pages[0];
            window.$utils = ctx.utils;
            window.$opts = window.$options = ctx.options;
            window.$this = ctx.__debugThis__;
            window.$get = fieldId => ctx.__debugThis__.$.call(window.$this, fieldId);
            window.$state = ctx.__debugThis__ && ctx.__debugThis__.state;
            window.$state$ = JSON.parse(JSON.stringify(window.$state || {}));
            window.$rawComponents = ctx.rawComponents;
            window.$components = ctx.components;
        }

        if (window.VisualEngine && VisualEngine.Pages) {
            definePropertyWithGetter('$curDoc', 'VisualEngine.Pages.currentDocument');
            definePropertyWithGetter('$rootNode', 'VisualEngine.Pages.currentDocument.rootNode');
            definePropertyWithGetter('$project', 'VisualEngine.Pages.currentDocument.project');
            definePropertyWithGetter('$designer', 'VisualEngine.Pages.currentDocument.project.designer');
            definePropertyWithGetter('$docs', 'VisualEngine.Pages.currentDocument.project.documents');
            definePropertyWithGetter('$docsMap', 'VisualEngine.Pages.currentDocument.project.documentsMap');
            definePropertyWithGetter('$nodes', 'VisualEngine.Pages.currentDocument.nodes');
            definePropertyWithGetter('$nodesMap', 'VisualEngine.Pages.currentDocument.nodesMap');
            window.$getNode = nodeId => {
                return nodeId ?
                    VisualEngine.Pages.currentDocument.nodesMap.get(nodeId) :
                    VisualEngine.Exchange.getSelected();
            }
        }
    }, 1000);
})();