LowCodeEngine

try to take over the world!

  1. // ==UserScript==
  2. // @name LowCodeEngine
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://*/*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11. /* eslint-disable */
  12.  
  13. function safeGet(target, paths, defaultValue) {
  14. const safeGetRegex = /\[|(?:\]\[?)|\./g;
  15. if (typeof paths === 'string') {
  16. paths = paths.split(safeGetRegex).filter(p => !!p);
  17. }
  18. if (target) {
  19. const result = paths.some(p => {
  20. target = target[p];
  21. if (target === null || target === undefined) {
  22. return true;
  23. }
  24. });
  25. return result ? defaultValue : target;
  26. }
  27. return target;
  28. }
  29.  
  30. const settedMap = {};
  31. function defineProperty(name, descriptor) {
  32. if (window[name]) return;
  33. Object.defineProperty(window, name, descriptor);
  34. }
  35.  
  36. function definePropertyWithGetter(name, path) {
  37. if (settedMap[name]) return;
  38. settedMap[name] = true;
  39. defineProperty(name, { get() { return safeGet(window, path); } });
  40. }
  41.  
  42. (function() {
  43. 'use strict';
  44. let tries = 0;
  45. const maxTries = 10;
  46. // if (window.RenderEngine) return;
  47. const iterId = setInterval(function() {
  48. if (tries++ >= maxTries) clearInterval(iterId);
  49.  
  50. if (window.LeGao && window.LeGao.getContext && window.LeGao.getContext()) {
  51. clearInterval(iterId);
  52. const ctx = LeGao.getContext();
  53. window.$ctx = ctx;
  54. window.$schema = ctx.schema;
  55. window.$page = ctx.schema.pages && ctx.schema.pages[0];
  56. window.$utils = ctx.utils;
  57. window.$opts = window.$options = ctx.options;
  58. window.$this = ctx.__debugThis__;
  59. window.$get = fieldId => ctx.__debugThis__.$.call(window.$this, fieldId);
  60. window.$state = ctx.__debugThis__ && ctx.__debugThis__.state;
  61. window.$state$ = JSON.parse(JSON.stringify(window.$state || {}));
  62. window.$rawComponents = ctx.rawComponents;
  63. window.$components = ctx.components;
  64. }
  65.  
  66. if (window.VisualEngine && VisualEngine.Pages) {
  67. definePropertyWithGetter('$curDoc', 'VisualEngine.Pages.currentDocument');
  68. definePropertyWithGetter('$rootNode', 'VisualEngine.Pages.currentDocument.rootNode');
  69. definePropertyWithGetter('$project', 'VisualEngine.Pages.currentDocument.project');
  70. definePropertyWithGetter('$designer', 'VisualEngine.Pages.currentDocument.project.designer');
  71. definePropertyWithGetter('$docs', 'VisualEngine.Pages.currentDocument.project.documents');
  72. definePropertyWithGetter('$docsMap', 'VisualEngine.Pages.currentDocument.project.documentsMap');
  73. definePropertyWithGetter('$nodes', 'VisualEngine.Pages.currentDocument.nodes');
  74. definePropertyWithGetter('$nodesMap', 'VisualEngine.Pages.currentDocument.nodesMap');
  75. window.$getNode = nodeId => {
  76. return nodeId ?
  77. VisualEngine.Pages.currentDocument.nodesMap.get(nodeId) :
  78. VisualEngine.Exchange.getSelected();
  79. }
  80. }
  81. }, 1000);
  82. })();