@lukaskj/xmonkey 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/cjs/decorators/console-script.decorator.d.ts +3 -0
- package/dist/cjs/decorators/console-script.decorator.js +13 -0
- package/dist/cjs/decorators/ui-script.decorator.d.ts +4 -0
- package/dist/cjs/decorators/ui-script.decorator.js +25 -0
- package/dist/cjs/esbuild/build.d.ts +1 -0
- package/dist/cjs/esbuild/build.js +100 -0
- package/dist/cjs/esbuild/plugins/xmonkey-strip-metadata-plugin.d.ts +2 -0
- package/dist/cjs/esbuild/plugins/xmonkey-strip-metadata-plugin.js +142 -0
- package/dist/cjs/esbuild/plugins/xmonkey-styles-plugin.d.ts +2 -0
- package/dist/cjs/esbuild/plugins/xmonkey-styles-plugin.js +85 -0
- package/dist/cjs/example-scripts/example-console-script.d.ts +4 -0
- package/dist/cjs/example-scripts/example-console-script.js +87 -0
- package/dist/cjs/example-scripts/example-ui-script.d.ts +6 -0
- package/dist/cjs/example-scripts/example-ui-script.js +40 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/interfaces/console-script.interface.d.ts +6 -0
- package/dist/cjs/interfaces/console-script.interface.js +7 -0
- package/dist/cjs/interfaces/index.d.ts +2 -0
- package/dist/cjs/interfaces/index.js +18 -0
- package/dist/cjs/interfaces/ui-script.interface.d.ts +5 -0
- package/dist/cjs/interfaces/ui-script.interface.js +2 -0
- package/dist/cjs/types.d.ts +28 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/ui/x-monkey-window-component.d.ts +7 -0
- package/dist/cjs/ui/x-monkey-window-component.js +18 -0
- package/dist/cjs/utils/is-null-or-undefined.d.ts +2 -0
- package/dist/cjs/utils/is-null-or-undefined.js +9 -0
- package/dist/cjs/utils/sleep.d.ts +1 -0
- package/dist/cjs/utils/sleep.js +7 -0
- package/dist/esm/decorators/console-script.decorator.d.ts +3 -0
- package/dist/esm/decorators/console-script.decorator.js +9 -0
- package/dist/esm/decorators/ui-script.decorator.d.ts +4 -0
- package/dist/esm/decorators/ui-script.decorator.js +21 -0
- package/dist/esm/esbuild/build.d.ts +1 -0
- package/dist/esm/esbuild/build.js +73 -0
- package/dist/esm/esbuild/plugins/xmonkey-strip-metadata-plugin.d.ts +2 -0
- package/dist/esm/esbuild/plugins/xmonkey-strip-metadata-plugin.js +138 -0
- package/dist/esm/esbuild/plugins/xmonkey-styles-plugin.d.ts +2 -0
- package/dist/esm/esbuild/plugins/xmonkey-styles-plugin.js +81 -0
- package/dist/esm/example-scripts/example-console-script.d.ts +4 -0
- package/dist/esm/example-scripts/example-console-script.js +84 -0
- package/dist/esm/example-scripts/example-ui-script.d.ts +6 -0
- package/dist/esm/example-scripts/example-ui-script.js +37 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/interfaces/console-script.interface.d.ts +6 -0
- package/dist/esm/interfaces/console-script.interface.js +6 -0
- package/dist/esm/interfaces/index.d.ts +2 -0
- package/dist/esm/interfaces/index.js +2 -0
- package/dist/esm/interfaces/ui-script.interface.d.ts +5 -0
- package/dist/esm/interfaces/ui-script.interface.js +1 -0
- package/dist/esm/types.d.ts +28 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/x-monkey-window-component.d.ts +7 -0
- package/dist/esm/ui/x-monkey-window-component.js +14 -0
- package/dist/esm/utils/is-null-or-undefined.d.ts +2 -0
- package/dist/esm/utils/is-null-or-undefined.js +4 -0
- package/dist/esm/utils/sleep.d.ts +1 -0
- package/dist/esm/utils/sleep.js +3 -0
- package/package.json +85 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ScriptInfo = {
|
|
2
|
+
"@name": string;
|
|
3
|
+
"@namespace": string;
|
|
4
|
+
"@match": string;
|
|
5
|
+
"@version": string;
|
|
6
|
+
"@author": string;
|
|
7
|
+
"@description": string;
|
|
8
|
+
"@grant"?: string[];
|
|
9
|
+
[k: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type NonFunctionPropertyNames<T> = {
|
|
12
|
+
[K in keyof T]: T[K] extends Function ? never : K;
|
|
13
|
+
}[keyof T];
|
|
14
|
+
export type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
|
|
15
|
+
export type FunctionPropertyNames<T> = {
|
|
16
|
+
[K in keyof T]: T[K] extends Function ? K : never;
|
|
17
|
+
}[keyof T];
|
|
18
|
+
export type ClassConstructor<T> = {
|
|
19
|
+
new (..._: any[]): T;
|
|
20
|
+
};
|
|
21
|
+
export type Self<T> = ClassConstructor<T>;
|
|
22
|
+
export type AnyObject = {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
};
|
|
25
|
+
export type AnyType = string | number | boolean | AnyObject;
|
|
26
|
+
export type WithRequired<T, K extends keyof T> = T & {
|
|
27
|
+
[P in K]-?: T[P];
|
|
28
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XMonkeyWindowComponent = void 0;
|
|
4
|
+
var jsx_runtime_1 = require("preact/jsx-runtime");
|
|
5
|
+
var hooks_1 = require("preact/hooks");
|
|
6
|
+
function XMonkeyWindowComponent(props) {
|
|
7
|
+
var _a = (0, hooks_1.useState)(false), minimized = _a[0], setMinimized = _a[1];
|
|
8
|
+
function toggleMinimize() {
|
|
9
|
+
setMinimized(!minimized);
|
|
10
|
+
}
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "xmwr_c d--f fd--c ai--c jc--sb", children: [(0, jsx_runtime_1.jsxs)("div", { className: "xmwr-h w-100 m0 d--f fd--r jc--c bg-primary noselect", children: [(0, jsx_runtime_1.jsx)("div", { className: "xmwr-title m0", children: props.title }), (0, jsx_runtime_1.jsx)(MinimizeButton, { toggleMinimize: toggleMinimize, minimized: minimized })] }), (0, jsx_runtime_1.jsx)("div", { className: "xmwr-b w-100 d--f jc--c " + (minimized ? "b-collapsed" : ""), children: props.children })] }));
|
|
12
|
+
}
|
|
13
|
+
exports.XMonkeyWindowComponent = XMonkeyWindowComponent;
|
|
14
|
+
function MinimizeButton(_a) {
|
|
15
|
+
var minimized = _a.minimized, toggleMinimize = _a.toggleMinimize;
|
|
16
|
+
var minimizeChar = minimized ? "+" : "-";
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "xmwr-x m0", onClick: function () { return toggleMinimize(); }, children: minimizeChar }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNullOrEmptyOrUndefined = exports.isNullOrUndefined = void 0;
|
|
4
|
+
var isNullOrUndefined = function (value) { return value === null || value === undefined; };
|
|
5
|
+
exports.isNullOrUndefined = isNullOrUndefined;
|
|
6
|
+
function isNullOrEmptyOrUndefined(value) {
|
|
7
|
+
return (0, exports.isNullOrUndefined)(value) || value === "" || value.toString().trim() === "";
|
|
8
|
+
}
|
|
9
|
+
exports.isNullOrEmptyOrUndefined = isNullOrEmptyOrUndefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { h, render } from "preact";
|
|
2
|
+
import { XMonkeyWindowComponent } from "../ui/x-monkey-window-component";
|
|
3
|
+
import "../ui/styles/base.scss";
|
|
4
|
+
export function UiScript(_metadata) {
|
|
5
|
+
return function (_target) {
|
|
6
|
+
var _a;
|
|
7
|
+
var scriptObject = new _target();
|
|
8
|
+
var rootComponent = xMonkeyWrapperElement();
|
|
9
|
+
render(h(XMonkeyWindowComponent, { title: (_a = scriptObject.title) !== null && _a !== void 0 ? _a : "" }, scriptObject.render()), rootComponent);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function xMonkeyWrapperElement() {
|
|
13
|
+
var ID = "__xmwr";
|
|
14
|
+
var div = document.getElementById(ID);
|
|
15
|
+
if (div)
|
|
16
|
+
return div;
|
|
17
|
+
div = document.createElement("div");
|
|
18
|
+
div.id = ID;
|
|
19
|
+
document.body.appendChild(div);
|
|
20
|
+
return div;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildXmonkeyScript(scriptBasePath: string): Promise<void>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import * as esbuild from "esbuild";
|
|
38
|
+
import { sassPlugin } from "esbuild-sass-plugin";
|
|
39
|
+
import { xMonkeyStripMetadataPlugin } from "./plugins/xmonkey-strip-metadata-plugin.js";
|
|
40
|
+
import { xMonkeyStylesPlugin } from "./plugins/xmonkey-styles-plugin.js";
|
|
41
|
+
export function buildXmonkeyScript(scriptBasePath) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
+
var entryFile;
|
|
44
|
+
return __generator(this, function (_a) {
|
|
45
|
+
switch (_a.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
entryFile = scriptBasePath;
|
|
48
|
+
console.info("Building file: '".concat(entryFile, "'"));
|
|
49
|
+
return [4, esbuild.build({
|
|
50
|
+
entryPoints: [entryFile],
|
|
51
|
+
outfile: "dist/index.js",
|
|
52
|
+
bundle: true,
|
|
53
|
+
treeShaking: true,
|
|
54
|
+
minify: process.env.DEBUG ? false : true,
|
|
55
|
+
platform: "browser",
|
|
56
|
+
format: "iife",
|
|
57
|
+
sourcemap: false,
|
|
58
|
+
keepNames: true,
|
|
59
|
+
logLevel: "info",
|
|
60
|
+
metafile: true,
|
|
61
|
+
plugins: [
|
|
62
|
+
xMonkeyStripMetadataPlugin(),
|
|
63
|
+
sassPlugin({ style: "compressed" }),
|
|
64
|
+
xMonkeyStylesPlugin(),
|
|
65
|
+
],
|
|
66
|
+
})];
|
|
67
|
+
case 1:
|
|
68
|
+
_a.sent();
|
|
69
|
+
return [2];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { readFile, writeFile } from "fs/promises";
|
|
38
|
+
export function xMonkeyStripMetadataPlugin() {
|
|
39
|
+
return {
|
|
40
|
+
name: "xmonkey-strip-metadata-plugin",
|
|
41
|
+
setup: function (build) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
var foundMetadata = false;
|
|
44
|
+
var metadataContent = "";
|
|
45
|
+
build.onLoad({ filter: /.(ts|tsx)/, namespace: "file" }, function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
46
|
+
var source, scriptMetadataIndex, regex, metadataDecoratorMatcher, startJsonMetadataIndex, endJsonMetadataIndex, metadataJsonString, contents, extension, loader;
|
|
47
|
+
var _a;
|
|
48
|
+
return __generator(this, function (_b) {
|
|
49
|
+
switch (_b.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
if (foundMetadata)
|
|
52
|
+
return [2];
|
|
53
|
+
return [4, readFile(args.path, "utf8")];
|
|
54
|
+
case 1:
|
|
55
|
+
source = _b.sent();
|
|
56
|
+
scriptMetadataIndex = (_a = source.match(/@(ConsoleScript|UiScript)\(/)) === null || _a === void 0 ? void 0 : _a.index;
|
|
57
|
+
if (!scriptMetadataIndex || scriptMetadataIndex < 0)
|
|
58
|
+
return [2];
|
|
59
|
+
foundMetadata = true;
|
|
60
|
+
regex = /\@(ConsoleScript|UiScript)\([^\)]*\)(\.[^\)]*\))?/gi;
|
|
61
|
+
metadataDecoratorMatcher = source.match(regex);
|
|
62
|
+
if (metadataDecoratorMatcher) {
|
|
63
|
+
metadataContent = metadataDecoratorMatcher.at(0);
|
|
64
|
+
startJsonMetadataIndex = metadataContent.indexOf("{");
|
|
65
|
+
endJsonMetadataIndex = metadataContent.lastIndexOf("}");
|
|
66
|
+
metadataJsonString = metadataContent.substring(startJsonMetadataIndex, endJsonMetadataIndex + 1);
|
|
67
|
+
contents = source.replace(metadataJsonString, "");
|
|
68
|
+
extension = args.path.split(".").pop();
|
|
69
|
+
loader = extension === "tsx" ? "tsx" : "ts";
|
|
70
|
+
return [2, { contents: contents, loader: loader }];
|
|
71
|
+
}
|
|
72
|
+
return [2];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}); });
|
|
76
|
+
build.onEnd(function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
77
|
+
var fileContents, scriptMetadataString;
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (!((_a = build.initialOptions) === null || _a === void 0 ? void 0 : _a.outfile) || !((_b = build.initialOptions) === null || _b === void 0 ? void 0 : _b.bundle)) {
|
|
83
|
+
console.error("Wrong build configuration. Options 'bundle' must be enabled and 'outfile' must be set.");
|
|
84
|
+
return [2];
|
|
85
|
+
}
|
|
86
|
+
if (!foundMetadata) {
|
|
87
|
+
console.error("ScriptMetadata decorator not found.");
|
|
88
|
+
return [2];
|
|
89
|
+
}
|
|
90
|
+
if (result.errors.length) {
|
|
91
|
+
console.error("Error building. Script Metadata cannot be added to final script.");
|
|
92
|
+
return [2];
|
|
93
|
+
}
|
|
94
|
+
return [4, readFile(build.initialOptions.outfile)];
|
|
95
|
+
case 1:
|
|
96
|
+
fileContents = _c.sent();
|
|
97
|
+
scriptMetadataString = getScriptMetadataString(metadataContent);
|
|
98
|
+
return [4, writeFile(build.initialOptions.outfile, "".concat(scriptMetadataString, "\n\n").concat(fileContents.toString()))];
|
|
99
|
+
case 2:
|
|
100
|
+
_c.sent();
|
|
101
|
+
return [2];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); });
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function getScriptMetadataString(scriptMetadataFunctionCallString) {
|
|
109
|
+
scriptMetadataFunctionCallString = scriptMetadataFunctionCallString.trim();
|
|
110
|
+
var startJsonMetadataIndex = scriptMetadataFunctionCallString.indexOf("{");
|
|
111
|
+
var endJsonMetadataIndex = scriptMetadataFunctionCallString.lastIndexOf("}");
|
|
112
|
+
if (startJsonMetadataIndex < 0 || endJsonMetadataIndex < 0) {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
var metadataObject = JSON.parse(scriptMetadataFunctionCallString
|
|
116
|
+
.substring(startJsonMetadataIndex, endJsonMetadataIndex + 1)
|
|
117
|
+
.replaceAll("\n", "")
|
|
118
|
+
.replaceAll(",}", "}"));
|
|
119
|
+
var tag = "// ==UserScript==";
|
|
120
|
+
var tagEnd = "// ==/UserScript==";
|
|
121
|
+
var headersArr = [];
|
|
122
|
+
var spaces = 13;
|
|
123
|
+
var _loop_1 = function (key) {
|
|
124
|
+
if (Array.isArray(metadataObject[key])) {
|
|
125
|
+
metadataObject[key].forEach(function (item) {
|
|
126
|
+
headersArr.push("".concat(key.padEnd(spaces, " ")).concat(item));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
headersArr.push("".concat(key.padEnd(spaces, " ")).concat(metadataObject[key]));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
for (var key in metadataObject) {
|
|
134
|
+
_loop_1(key);
|
|
135
|
+
}
|
|
136
|
+
var headers = headersArr.map(function (h) { return "// ".concat(h); }).join("\n");
|
|
137
|
+
return "".concat(tag, "\n").concat(headers, "\n").concat(tagEnd);
|
|
138
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { appendFile, readFile } from "fs/promises";
|
|
38
|
+
export function xMonkeyStylesPlugin() {
|
|
39
|
+
return {
|
|
40
|
+
name: "xmonkey-styles-plugin",
|
|
41
|
+
setup: function (build) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
build.onEnd(function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
+
var outputs, cssFilePath, file, ext, jsOutFile, cssContents;
|
|
45
|
+
var _a, _b;
|
|
46
|
+
return __generator(this, function (_c) {
|
|
47
|
+
switch (_c.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
if (!((_a = build.initialOptions) === null || _a === void 0 ? void 0 : _a.outfile) || !((_b = build.initialOptions) === null || _b === void 0 ? void 0 : _b.bundle)) {
|
|
50
|
+
console.error("Wrong build configuration. Options 'bundle' must be enabled and 'outfile' must be set.");
|
|
51
|
+
return [2];
|
|
52
|
+
}
|
|
53
|
+
if (!result.metafile) {
|
|
54
|
+
console.warn("ESBuild metafile not enabled. Style bundle skipped.");
|
|
55
|
+
return [2];
|
|
56
|
+
}
|
|
57
|
+
outputs = result.metafile.outputs;
|
|
58
|
+
cssFilePath = "";
|
|
59
|
+
for (file in outputs) {
|
|
60
|
+
ext = file.split(".").pop();
|
|
61
|
+
if (ext === "css") {
|
|
62
|
+
cssFilePath = file;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!cssFilePath.length) {
|
|
67
|
+
console.warn("CSS output not generated. Style bundle skipped.");
|
|
68
|
+
return [2];
|
|
69
|
+
}
|
|
70
|
+
jsOutFile = build.initialOptions.outfile;
|
|
71
|
+
return [4, readFile(cssFilePath)];
|
|
72
|
+
case 1:
|
|
73
|
+
cssContents = (_c.sent()).toString();
|
|
74
|
+
appendFile(jsOutFile, "\nGM.addStyle(\"\\\n".concat(cssContents.trim(), "\\\n\");"));
|
|
75
|
+
return [2];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}); });
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
17
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
18
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
19
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
20
|
+
function step(op) {
|
|
21
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
22
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
23
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
24
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
25
|
+
switch (op[0]) {
|
|
26
|
+
case 0: case 1: t = op; break;
|
|
27
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
28
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
29
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
30
|
+
default:
|
|
31
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
32
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
33
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
34
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
35
|
+
if (t[2]) _.ops.pop();
|
|
36
|
+
_.trys.pop(); continue;
|
|
37
|
+
}
|
|
38
|
+
op = body.call(thisArg, _);
|
|
39
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
40
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
import { ConsoleScript } from "../decorators/console-script.decorator";
|
|
44
|
+
import { sleep } from "../utils/sleep";
|
|
45
|
+
var ExampleConsoleScript = (function () {
|
|
46
|
+
function ExampleConsoleScript() {
|
|
47
|
+
}
|
|
48
|
+
ExampleConsoleScript.prototype.execute = function () {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
50
|
+
var i;
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0:
|
|
54
|
+
i = 0;
|
|
55
|
+
_a.label = 1;
|
|
56
|
+
case 1:
|
|
57
|
+
if (!(i < 50)) return [3, 4];
|
|
58
|
+
console.log("Executing script...", i + 1, location.href);
|
|
59
|
+
return [4, sleep(20)];
|
|
60
|
+
case 2:
|
|
61
|
+
_a.sent();
|
|
62
|
+
_a.label = 3;
|
|
63
|
+
case 3:
|
|
64
|
+
i++;
|
|
65
|
+
return [3, 1];
|
|
66
|
+
case 4: return [2];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
ExampleConsoleScript = __decorate([
|
|
72
|
+
ConsoleScript({
|
|
73
|
+
"@name": "Example Console Script",
|
|
74
|
+
"@namespace": "console-scripts",
|
|
75
|
+
"@match": "https://en.wikipedia.org/*",
|
|
76
|
+
"@version": "1.0",
|
|
77
|
+
"@author": "-",
|
|
78
|
+
"@description": "Example Console Script Description",
|
|
79
|
+
"@grant": ["GM.addStyle"],
|
|
80
|
+
})
|
|
81
|
+
], ExampleConsoleScript);
|
|
82
|
+
return ExampleConsoleScript;
|
|
83
|
+
}());
|
|
84
|
+
export { ExampleConsoleScript };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
8
|
+
import { UiScript } from "../decorators/ui-script.decorator";
|
|
9
|
+
import { useState } from "preact/hooks";
|
|
10
|
+
import "./example-scss.scss";
|
|
11
|
+
var ExampleUiScript = (function () {
|
|
12
|
+
function ExampleUiScript() {
|
|
13
|
+
this.title = "Example UI Script";
|
|
14
|
+
}
|
|
15
|
+
ExampleUiScript.prototype.render = function () {
|
|
16
|
+
return _jsx(JsxUiExample, {});
|
|
17
|
+
};
|
|
18
|
+
ExampleUiScript = __decorate([
|
|
19
|
+
UiScript({
|
|
20
|
+
"@name": "Example Console Script",
|
|
21
|
+
"@namespace": "console-scripts",
|
|
22
|
+
"@match": "https://en.wikipedia.org/*",
|
|
23
|
+
"@version": "1.0",
|
|
24
|
+
"@author": "-",
|
|
25
|
+
"@description": "Example Console Script Description",
|
|
26
|
+
"@grant": ["GM.addStyle"],
|
|
27
|
+
})
|
|
28
|
+
], ExampleUiScript);
|
|
29
|
+
return ExampleUiScript;
|
|
30
|
+
}());
|
|
31
|
+
export { ExampleUiScript };
|
|
32
|
+
function JsxUiExample() {
|
|
33
|
+
var _a = useState(0), count = _a[0], setCount = _a[1];
|
|
34
|
+
var increment = function () { return setCount(count + 1); };
|
|
35
|
+
var decrement = function () { return setCount(function (currentCount) { return currentCount - 1; }); };
|
|
36
|
+
return (_jsxs(_Fragment, { children: [_jsxs("p", { children: ["Count: ", count] }), _jsxs("div", { class: "w-100 d--f jc--c", children: [_jsx("button", { class: "btn small primary", onClick: increment, children: "Increment" }), _jsx("button", { class: "btn small primary", onClick: decrement, children: "Decrement" })] })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { buildXmonkeyScript } from "./esbuild/build";
|
|
2
|
+
var entryFile = process.argv[2];
|
|
3
|
+
if (!entryFile) {
|
|
4
|
+
console.error("No entryfile specified. Try adding the script to build in the argument.");
|
|
5
|
+
console.error("Example: npm run build src/example-script.ts");
|
|
6
|
+
process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
buildXmonkeyScript(entryFile);
|
|
9
|
+
export * from "./decorators/console-script.decorator";
|
|
10
|
+
export * from "./decorators/ui-script.decorator";
|
|
11
|
+
export * from "./interfaces";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|