-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.user.js
More file actions
181 lines (147 loc) · 5.01 KB
/
test.user.js
File metadata and controls
181 lines (147 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// ==UserScript==
// @name Test
// @namespace https://github.com/nexushoratio/userscripts
// @match http://localhost:8000/*
// @noframes
// @version 12
// @author Mike Castle
// @description Just for running tests.
// @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0-standalone.html
// @require https://greasyfork.org/scripts/478188-nh-xunit/code/NH_xunit.js
// @require https://greasyfork.org/scripts/477290-nh-base/code/NH_base.js
// @require https://greasyfork.org/scripts/478349-nh-userscript/code/NH_userscript.js
// @require https://greasyfork.org/scripts/478440-nh-web/code/NH_web.js
// @require https://greasyfork.org/scripts/478676-nh-widget/code/NH_widget.js
// @require https://greasyfork.org/scripts/570146-nh-spa/code/NH_spa.js
// @grant GM.getValue
// @grant GM.setValue
// @grant window.onurlchange
// ==/UserScript==
// eslint-disable-next-line max-lines-per-function
(async () => {
'use strict';
const NH = window.NexusHoratio.base.ensure([
{name: 'xunit'},
{name: 'base'},
{name: 'userscript'},
{name: 'widget'},
{name: 'spa'},
]);
NH.xunit.testing.enabled = true;
await NH.userscript.setAutoManageLoggerConfigs(true);
const logger = new NH.base.Logger('Testing');
logger.log('starting');
for (const entry of NH.userscript.environmentData()) {
logger.log(entry);
}
NH.xunit.testing.run();
logger.log('finished');
/* eslint-disable max-lines-per-function */
/* eslint-disable require-jsdoc */
function demoGrid() {
function renderInt(record, field) {
return `${record[field]}`;
}
function renderType(record) {
return `${record.stage}, ${record.species}`;
}
function rowClassesFunc(record) {
return [record.species, record.stage];
}
const data = [
{id: 1, name: 'Sally', species: 'human', stage: 'juvenile'},
{name: 'Puff', id: 3, species: 'feline', stage: 'juvenile'},
{name: 'Jane', id: 2, species: 'human', stage: 'juvenile'},
{name: 'Bob', id: 4, species: 'alien', stage: 'adolescent'},
{name: 'Mother', id: 5, species: 'human', stage: 'adult'},
];
const w = new NH.widget.Grid('Characters')
.rowClassesFunc(rowClassesFunc)
.set(data);
w.installStyle(w.id, [
`#${w.container.id} {border-collapse: collapse;}`,
`#${w.container.id} td,th {border: 1px solid black;}`,
`#${w.container.id} tr {background-blend-mode: screen;}`,
`#${w.container.id} tr.feline {background-color: orange;}`,
`#${w.container.id} tr.human {background-color: RebeccaPurple;}`,
`#${w.container.id} tr.alien {background-color: green;}`,
`#${w.container.id} tr.juvenile {background-image: ` +
'linear-gradient(to bottom, white, black);}',
`#${w.container.id} tr.adolescent {background-image: ` +
'linear-gradient(to bottom, white, black, white);}',
`#${w.container.id} tr.adult {background-image: ` +
'linear-gradient(to bottom, white, black, white, black);}',
`#${w.container.id} td.typ {font-weight: bolder;}`,
]);
w.columns.push(
new NH.widget.GridColumn('id')
.renderFunc(renderInt),
new NH.widget.GridColumn('name'),
new NH.widget.GridColumn('typ')
.setTitle('Type')
.renderFunc(renderType),
);
w.build();
document.body.append(w.container);
}
class DemoDetails extends NH.spa.Details {}
class Global extends NH.spa.Page {
/** @param {NH.spa.SPA} spa - SPA instance that manages this Page. */
constructor(spa) {
super({spa: spa});
this.dispatcher.on('activate', this.#onActivate);
}
#onActivate = () => {
this.logger.log('hello');
}
}
class Slash extends NH.spa.Page {
/** @param {NH.spa.SPA} spa - SPA instance that manages this Page. */
constructor(spa) {
super({spa: spa, ...Slash.#details});
this.dispatcher.on('activate', this.#onActivate);
}
/** @type {NH.spa.Page~PageDetails} */
static #details = {
pathname: '/',
};
#onActivate = () => {
this.logger.log('world');
}
}
// Localhost:8000 happens to point to my local copy of this git workspace.
class Libby extends NH.spa.Page {
/** @param {NH.spa.SPA} spa - SPA instance that manages this Page. */
constructor(spa) {
super({spa: spa, ...Libby.#details});
this.dispatcher.on('activate', this.#onActivate);
}
/** @type {NH.spa.Page~PageDetails} */
static #details = {
pathname: '/lib/',
};
#onActivate = () => {
this.logger.log('libby');
}
}
function demoSpa() {
const deets = new DemoDetails();
const spa = new NH.spa.SPA(deets);
spa
.register(Global)
.register(Libby)
.register(Slash);
logger.log('deets', deets);
logger.log('spa', spa);
}
/* eslint-enable */
const demos = [
{enabled: false, demo: demoGrid},
{enabled: false, demo: demoSpa},
];
for (const {enabled, demo} of demos) {
if (enabled) {
demo();
}
}
})();