-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOS2.ergebnisse.user.js
3482 lines (2965 loc) · 143 KB
/
OS2.ergebnisse.user.js
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name OS2.ergebnisse
// @namespace http://os.ongapo.com/
// @version 0.32+WE+
// @copyright 2016+
// @author Sven Loges (SLC)
// @description Aktiviert als Standard die Option "Ergebnisse anzeigen" fuer Online Soccer 2.0
// @include /^https?://(www\.)?(os\.ongapo\.com|online-soccer\.eu|os-zeitungen\.com)/(l[sp]|os(eq?|c(q|[hzf]r))|supercup|zer)\.php(\?\S+(&\S+)*)?$/
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.deleteValue
// @grant GM.registerMenuCommand
// @grant GM.info
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_registerMenuCommand
// @grant GM_info
// ==/UserScript==
// ECMAScript 6:
/* jshint esnext: true */
/* jshint moz: true */
// ==================== Konfigurations-Abschnitt fuer Optionen ====================
const __LOGLEVEL = 3;
// Options-Typen
const __OPTTYPES = {
'MC' : "multiple choice",
'SW' : "switch",
'TF' : "true/false",
'SD' : "simple data",
'SI' : "simple option"
};
// Options-Typen
const __OPTACTION = {
'SET' : "set option value",
'NXT' : "set next option value",
'RST' : "reset options"
};
const __OPTMEM = {
'normal' : {
'Name' : "Browser",
'Value' : localStorage,
'Display' : "localStorage",
'Prefix' : 'run'
},
'begrenzt' : {
'Name' : "Session",
'Value' : sessionStorage,
'Display' : "sessionStorage",
'Prefix' : 'run'
},
'inaktiv' : {
'Name' : "inaktiv",
'Value' : undefined,
'Display' : "",
'Prefix' : ""
}
};
// Moegliche Optionen (hier die Standardwerte editieren oder ueber das Benutzermenu setzen):
const __OPTCONFIG = {
'showErgs' : { // Standardeinstellung der Ergebnisanzeige
'Name' : "showErgs",
'Type' : __OPTTYPES.SW,
'Default' : true,
'Action' : __OPTACTION.NXT,
'Label' : "Ergebnisse anzeigen",
'Hotkey' : 'E',
'AltLabel' : "Keine Ergebnisse",
'AltHotkey' : 'K',
'FormLabel' : "Ergebnisse anzeigen"
},
'reset' : { // Optionen auf die "Werkseinstellungen" zuruecksetzen
'FormPrio' : undefined,
'Name' : "reset",
'Type' : __OPTTYPES.SI,
'Action' : __OPTACTION.RST,
'Label' : "Standard-Optionen",
'Hotkey' : 'O',
'FormLabel' : ""
},
'storage' : { // Browserspeicher fuer die Klicks auf Optionen
'FormPrio' : undefined,
'Name' : "storage",
'Type' : __OPTTYPES.MC,
'ValType' : 'String',
'Choice' : Object.keys(__OPTMEM),
'Action' : __OPTACTION.NXT,
'Label' : "Speicher: $",
'Hotkey' : 'c',
'FormLabel' : "Speicher:|$"
},
'oldStorage' : { // Vorheriger Browserspeicher fuer die Klicks auf Optionen
'FormPrio' : undefined,
'Name' : "oldStorage",
'Type' : __OPTTYPES.SD,
'PreInit' : true,
'AutoReset' : true,
'Hidden' : true
},
'showForm' : { // Optionen auf der Webseite (true = anzeigen, false = nicht anzeigen)
'FormPrio' : 1,
'Name' : "showForm",
'Type' : __OPTTYPES.SW,
'FormType' : __OPTTYPES.SI,
'Permanent' : true,
'Default' : false,
'Title' : "$V Optionen",
'Action' : __OPTACTION.NXT,
'Label' : "Optionen anzeigen",
'Hotkey' : 'a',
'AltTitle' : "$V schlie\xDFen",
'AltLabel' : "Optionen verbergen",
'AltHotkey' : 'v',
'FormLabel' : ""
}
};
// ==================== Invarianter Abschnitt fuer Optionen ====================
// Ein Satz von Logfunktionen, die je nach Loglevel zur Verfuegung stehen. Aufruf: __LOG[level](text)
const __LOG = {
'logFun' : [
console.error, // [0] Alert
console.error, // [1] Error
console.log, // [2] Log: Release
console.log, // [3] Log: Info
console.log, // [4] Log: Debug
console.log, // [5] Log: Verbose
console.log, // [6] Log: Very verbose
console.log // [7] Log: Testing
],
'init' : function(win, logLevel = 1) {
for (let level = 0; level < this.logFun.length; level++) {
this[level] = ((level > logLevel) ? function() { } : this.logFun[level]);
}
},
'stringify' : safeStringify, // JSON.stringify
'changed' : function(oldVal, newVal) {
const __OLDVAL = this.stringify(oldVal);
const __NEWVAL = this.stringify(newVal);
return ((__OLDVAL !== __NEWVAL) ? __OLDVAL + " => " : "") + __NEWVAL;
}
};
__LOG.init(window, __LOGLEVEL);
// Kompatibilitaetsfunktion zur Ermittlung des Namens einer Funktion (falle <Function>.name nicht vorhanden ist)
if (Function.prototype.name === undefined) {
Object.defineProperty(Function.prototype, 'name', {
get : function() {
return /function ([^(\s]*)/.exec(this.toString())[1];
}
});
}
// Ergaenzung fuer Strings: Links oder rechts auffuellen nach Vorlage
// padStr: Vorlage, z.B. "00" fuer zweistellige Zahlen
// padLeft: true = rechtsbuendig, false = linksbuendig
// clip: Abschneiden, falls zu lang
// return Rechts- oder linksbuendiger String, der so lang ist wie die Vorlage
String.prototype.pad = function(padStr, padLeft = true, clip = false) {
const __LEN = ((clip || (padStr.length > this.length)) ? padStr.length : this.length);
return (padLeft ? String(padStr + this).slice(- __LEN) : String(this + padStr).slice(0, __LEN));
};
// Ersetzt in einem String {0}, {1}, ... durch die entsprechenden Parameter
// arguments: Parameter, die fuer {0}, {1}, ... eingesetzt werden sollen
// return Resultierender String
String.prototype.format = function() {
const __ARGS = arguments;
return this.replace(/{(\d+)}/g, function(match, argIdx) {
const __ARG = __ARGS[argIdx];
return ((__ARG !== undefined) ? __ARG : match);
});
};
// Gibt eine Meldung in der Console aus und oeffnet ein Bestaetigungsfenster mit der Meldung
// label: Eine Ueberschrift
// message: Der Meldungs-Text
// data: Ein Wert. Ist er angegeben, wird er in der Console ausgegeben
// return Liefert die Parameter zurueck
function showAlert(label, message, data = undefined) {
__LOG[0](label + ": " + message);
if (data !== undefined) {
__LOG[2](data);
}
alert(label + "\n\n" + message);
return arguments;
}
// Gibt eine Meldung in der Console aus und oeffnet ein Bestaetigungsfenster
// mit der Meldung zu einer Exception oder einer Fehlermeldung
// label: Eine Ueberschrift
// ex: Exception oder sonstiges Fehlerobjekt
// return Liefert die showAlert()-Parameter zurueck
function showException(label, ex) {
if (ex && ex.message) { // Exception
showAlert(label, ex.message, ex);
} else { // sonstiger Fehler
showAlert(label, ex);
}
}
// Standard-Callback-Funktion fuer onRejected, also abgefangener Fehler
// in einer Promise bei Exceptions oder Fehler bzw. Rejections
// error: Parameter von reject() im Promise-Objekt, der von Promise.catch() erhalten wurde
// return Liefert die showAlert()-Parameter zurueck
function defaultCatch(error) {
try {
const __LABEL = `[${error.lineNumber}] ${__DBMOD.Name}`;
if (error && error.message) { // Exception
return showException(__LABEL, error.message, error);
} else {
return showException(__LABEL, error);
}
} catch (ex) {
return showException(`[${ex.lineNumber}] ${__DBMOD.Name}`, ex.message, ex);
}
}
// ==================== Abschnitt fuer Klasse Class ====================
function Class(className, baseClass, initFun) {
'use strict';
try {
const __BASE = ((baseClass !== undefined) ? baseClass : Object);
const __BASEPROTO = (__BASE ? __BASE.prototype : undefined);
const __BASECLASS = (__BASEPROTO ? __BASEPROTO.__class : undefined);
this.className = (className || '?');
this.baseClass = __BASECLASS;
Object.setConst(this, 'baseProto', __BASEPROTO, false);
if (! initFun) {
const __BASEINIT = (__BASECLASS || { }).init;
if (__BASEINIT) {
initFun = function() {
// Basisklassen-Init aufrufen...
return __BASEINIT.call(this, arguments);
};
} else {
initFun = function() {
// Basisklassen-Init fehlt (und Basisklasse ist nicht Object)...
return false;
};
}
}
console.assert((__BASE === null) || ((typeof __BASE) === 'function'), "No function:", __BASE);
console.assert((typeof initFun) === 'function', "Not a function:", initFun);
this.init = initFun;
} catch (ex) {
showAlert('[' + ex.lineNumber + "] Error in Class " + className, ex.message, ex);
}
}
Class.define = function(subClass, baseClass, members = undefined, initFun = undefined, createProto = true) {
return (subClass.prototype = subClass.subclass(baseClass, members, initFun, createProto));
};
Object.setConst = function(obj, item, value, config) {
return Object.defineProperty(obj, item, {
enumerable : false,
configurable : (config || true),
writable : false,
value : value
});
};
Object.setConst(Object.prototype, 'subclass', function(baseClass, members, initFun, createProto) {
'use strict';
try {
const __MEMBERS = (members || { });
const __CREATEPROTO = ((createProto === undefined) ? true : createProto);
console.assert((typeof this) === 'function', "Not a function:", this);
console.assert((typeof __MEMBERS) === 'object', "Not an object:", __MEMBERS);
const __CLASS = new Class(this.name || __MEMBERS.__name, baseClass, initFun || __MEMBERS.__init);
const __PROTO = (__CREATEPROTO ? Object.create(__CLASS.baseProto) : this.prototype);
for (let item in __MEMBERS) {
if ((item !== '__name') && (item !== '__init')) {
Object.setConst(__PROTO, item, __MEMBERS[item]);
}
}
Object.setConst(__PROTO, '__class', __CLASS, ! __CREATEPROTO);
return __PROTO;
} catch (ex) {
showAlert('[' + ex.lineNumber + "] Error in subclassing", ex.message, ex);
}
}, false);
Class.define(Object, null, {
'__init' : function() {
// Oberstes Basisklassen-Init...
return true;
},
'getClass' : function() {
return this.__class;
},
'getClassName' : function() {
const __CLASS = this.getClass();
return (__CLASS ? __CLASS.getName() : undefined);
},
'setConst' : function(item, value, config = undefined) {
return Object.setConst(this, item, value, config);
}
}, undefined, false);
Class.define(Function, Object);
Class.define(Class, Object, {
'getName' : function() {
return this.className;
}
});
// ==================== Ende Abschnitt fuer Klasse Class ====================
// ==================== Abschnitt fuer Klasse Delims ====================
// Basisklasse fuer die Verwaltung der Trennzeichen und Symbole von Pfaden
// delim: Trennzeichen zwischen zwei Ebenen (oder Objekt/Delims mit entsprechenden Properties)
// back: (Optional) Name des relativen Vaterverzeichnisses
// root: (Optional) Kennung vor dem ersten Trenner am Anfang eines absoluten Pfads
// home: (Optional) Kennung vor dem ersten Trenner am Anfang eines Pfads relativ zu Home
function Delims(delim, back, root, home) {
'use strict';
if ((typeof delim) === 'object') {
// Erster Parameter ist Objekt mit den Properties...
if (back === undefined) {
back = delim.back;
}
if (root === undefined) {
root = delim.root;
}
if (home === undefined) {
home = delim.home;
}
delim = delim.delim;
}
this.setDelim(delim);
this.setBack(back);
this.setRoot(root);
this.setHome(home);
}
Class.define(Delims, Object, {
'setDelim' : function(delim = undefined) {
this.delim = delim;
},
'setBack' : function(back = undefined) {
this.back = back;
},
'setRoot' : function(root = undefined) {
this.root = root;
},
'setHome' : function(home = undefined) {
this.home = home;
}
});
// ==================== Ende Abschnitt fuer Klasse Delims ====================
// ==================== Abschnitt fuer Klasse UriDelims ====================
// Basisklasse fuer die Verwaltung der Trennzeichen und Symbole von URIs
// delim: Trennzeichen zwischen zwei Ebenen (oder Objekt/Delims mit entsprechenden Properties)
// back: (Optional) Name des relativen Vaterverzeichnisses
// root: (Optional) Kennung vor dem ersten Trenner am Anfang eines absoluten Pfads
// home: (Optional) Kennung vor dem ersten Trenner am Anfang eines Pfads relativ zu Home
// scheme: (Optional) Trennzeichen fuer den Schema-/Protokollnamen vorne
// host: (Optional) Prefix fuer Hostnamen hinter dem Scheme-Trenner
// port: (Optional) Trennzeichen vor der Portangabe, falls vorhanden
// query: (Optional) Trennzeichen fuer die Query-Parameter hinter dem Pfad
// parSep: (Optional) Trennzeichen zwischen je zwei Parametern
// parAss: (Optional) Trennzwischen zwischen Key und Value
// node: (Optional) Trennzeichen fuer den Knotennamen hinten (Fragment, Kapitel)
function UriDelims(delim, back, root, home, scheme, host, port, query, qrySep, qryAss, node) {
'use strict';
if ((typeof delim) === 'object') {
// Erster Parameter ist Objekt mit den Properties...
if (scheme === undefined) {
scheme = delim.scheme;
}
if (host === undefined) {
host = delim.host;
}
if (port === undefined) {
port = delim.port;
}
if (query === undefined) {
query = delim.query;
}
if (qrySep === undefined) {
qrySep = delim.qrySep;
}
if (qryAss === undefined) {
qryAss = delim.qryAss;
}
if (node === undefined) {
node = delim.node;
}
}
Delims.call(this, delim, back, root, home);
this.setScheme(scheme);
this.setHost(host);
this.setPort(port);
this.setQuery(query);
this.setQrySep(qrySep);
this.setQryAss(qryAss);
this.setNode(node);
}
Class.define(UriDelims, Delims, {
'setScheme' : function(scheme = undefined) {
this.scheme = scheme;
},
'setHost' : function(host = undefined) {
this.host = host;
},
'setPort' : function(port = undefined) {
this.port = port;
},
'setQuery' : function(query = undefined) {
this.query = query;
},
'setQrySep' : function(qrySep = undefined) {
this.qrySep = qrySep;
},
'setQryAss' : function(qryAss = undefined) {
this.qryAss = qryAss;
},
'setNode' : function(node = undefined) {
this.node = node;
}
});
// ==================== Ende Abschnitt fuer Klasse UriDelims ====================
// ==================== Abschnitt fuer Klasse Path ====================
// Basisklasse fuer die Verwaltung eines Pfades
// homePath: Absoluter Startpfad als String
// delims: Objekt mit Trennern und Symbolen als Properties (oder Delims-Objekt)
// 'delim': Trennzeichen zwischen zwei Ebenen
// 'back': Name des relativen Vaterverzeichnisses
// 'root': Kennung vor dem ersten Trenner am Anfang eines absoluten Pfads
// 'home': Kennung vor dem ersten Trenner am Anfang eines Pfads relativ zu Home
function Path(homePath, delims) {
'use strict';
this.dirs = [];
this.setDelims(delims);
this.homeDirs = this.getDirs(homePath, { 'home' : "" });
this.home();
}
Class.define(Path, Object, {
'root' : function() {
this.dirs.splice(0, this.dirs.length);
},
'home' : function() {
this.dirs = this.homeDirs.slice();
},
'up' : function() {
this.dirs.pop();
},
'down' : function(subDir) {
this.dirs.push(subDir);
},
'setDelims' : function(delims = undefined) {
this.setConst('delims', new Delims(delims));
},
'setDelim' : function(delim = undefined) {
this.delims.setDelim(delim || '/');
},
'setBackDelim' : function(backDelim = undefined) {
this.delims.setBack(backDelim || "..");
},
'setRootDelim' : function(rootDelim = undefined) {
this.delims.setRoot(rootDelim || "");
},
'setHomeDelim' : function(homeDelim = undefined) {
this.delims.setHome(homeDelim || '~');
},
'setSchemeDelim' : function(schemeDelim = undefined) {
this.delims.setScheme(schemeDelim || ':');
},
'setHostDelim' : function(hostDelim = undefined) {
this.delims.setHost(hostDelim || '//');
},
'setPortDelim' : function(portDelim = undefined) {
this.delims.setHost(portDelim || ':');
},
'setQueryDelim' : function(queryDelim = undefined) {
this.delims.setQuery(queryDelim || '?');
},
'setParSepDelim' : function(parSepDelim = undefined) {
this.delims.setParSep(parSepDelim || '&');
},
'setParAssDelim' : function(parAssDelim = undefined) {
this.delims.setParAss(parAssDelim || '=');
},
'setNodeDelim' : function(nodeDelim = undefined) {
this.delims.setNode(nodeDelim || '#');
},
'getLeaf' : function(dirs = undefined) {
const __DIRS = (dirs || this.dirs);
return ((__DIRS && __DIRS.length) ? __DIRS.slice(-1)[0] : "");
},
'getPath' : function(dirs = undefined, delims = undefined) {
const __DELIMS = new Delims(delims);
const __DELIM = (__DELIMS.delim || this.delims.delim);
const __ROOTDELIM = ((__DELIMS.root !== undefined) ? __DELIMS.root : this.delims.root);
const __DIRS = (dirs || this.dirs);
return __ROOTDELIM + __DELIM + __DIRS.join(__DELIM);
},
'getDirs' : function(path = undefined, delims = undefined) {
const __DELIMS = new Delims(delims);
const __DELIM = (__DELIMS.delim || this.delims.delim);
const __ROOTDELIM = ((__DELIMS.root !== undefined) ? __DELIMS.root : this.delims.root);
const __HOMEDELIM = ((__DELIMS.home !== undefined) ? __DELIMS.home : this.delims.home);
const __DIRS = (path ? path.split(__DELIM) : []);
const __FIRST = __DIRS[0];
if (__FIRST && (__FIRST !== __ROOTDELIM) && (__FIRST !== __HOMEDELIM)) {
showAlert("Kein absoluter Pfad", this.getPath(__DIRS), this);
}
return __DIRS.slice(1);
}
});
// ==================== Ende Abschnitt fuer Klasse Path ====================
// ==================== Abschnitt fuer Klasse URI ====================
// Basisklasse fuer die Verwaltung einer URI/URL
// homePath: Absoluter Startpfad als String
// delims: Objekt mit Trennern und Symbolen als Properties (oder Delims-Objekt)
// 'delim': Trennzeichen zwischen zwei Ebenen
// 'back': Name des relativen Vaterverzeichnisses
// 'root': Kennung vor dem ersten Trenner am Anfang eines absoluten Pfads
// 'home': Kennung vor dem ersten Trenner am Anfang eines Pfads relativ zu Home
function URI(homePath, delims) {
'use strict';
Path.call(this);
const __HOSTPORT = this.getHostPort(homePath);
this.scheme = this.getSchemePrefix(homePath);
this.host = __HOSTPORT.host;
this.port = this.parseValue(__HOSTPORT.port);
this.query = this.parseQuery(this.getQueryString(homePath));
this.node = this.getNodeSuffix(homePath);
this.homeDirs = this.getDirs(homePath, { 'home' : "" });
this.home();
}
Class.define(URI, Path, {
'setDelims' : function() {
this.setConst('delims', new UriDelims('/', "..", "", '~', ':', "//", ':', '?', '&', '=', '#'));
},
'setSchemeDelim' : function(schemeDelim = undefined) {
this.delims.setScheme(schemeDelim || ':');
},
'setQueryDelim' : function(queryDelim = undefined) {
this.delims.setQuery(queryDelim || '?');
},
'setParSepDelim' : function(parSepDelim = undefined) {
this.delims.setParSep(parSepDelim || '&');
},
'setParAssDelim' : function(parAssDelim = undefined) {
this.delims.setParAss(parAssDelim || '=');
},
'setNodeDelim' : function(nodeDelim = undefined) {
this.delims.setNode(nodeDelim || '#');
},
'getServerPath' : function(path = undefined) {
return this.stripHostPort(this.stripQueryString(this.stripNodeSuffix(this.stripSchemePrefix(path))));
},
'getHostPort' : function(path = undefined) {
const __HOSTDELIM = this.delims.host;
const __PORTDELIM = this.delims.port;
const __ROOTDELIM = this.delims.root + this.delims.delim;
const __NOSCHEME = this.stripSchemePrefix(path);
const __INDEXHOST = (__NOSCHEME ? __NOSCHEME.indexOf(__HOSTDELIM) : -1);
const __PATH = ((~ __INDEXHOST) ? __NOSCHEME.substring(__INDEXHOST + __HOSTDELIM.length) : __NOSCHEME);
const __INDEXHOSTPORT = (__PATH ? __PATH.indexOf(__ROOTDELIM) : -1);
const __HOSTPORT = ((~ __INDEXHOSTPORT) ? __PATH.substring(0, __INDEXHOSTPORT) : undefined);
const __INDEXPORT = (__HOSTPORT ? __HOSTPORT.indexOf(__PORTDELIM) : -1);
const __HOST = ((~ __INDEXPORT) ? __HOSTPORT.substring(0, __INDEXPORT) : __HOSTPORT);
const __PORT = ((~ __INDEXPORT) ? __HOSTPORT.substring(__INDEXPORT + __PORTDELIM.length) : undefined);
return {
'host' : __HOST,
'port' : __PORT
};
},
'stripHostPort' : function(path = undefined) {
const __HOSTDELIM = this.delims.host;
const __ROOTDELIM = this.delims.root + this.delims.delim;
const __INDEXHOST = (path ? path.indexOf(__HOSTDELIM) : -1);
const __PATH = ((~ __INDEXHOST) ? path.substring(__INDEXHOST + __HOSTDELIM.length) : path);
const __INDEXHOSTPORT = (__PATH ? __PATH.indexOf(__ROOTDELIM) : -1);
return ((~ __INDEXHOSTPORT) ? __PATH.substring(__INDEXHOSTPORT) : __PATH);
},
'getSchemePrefix' : function(path = undefined) {
const __SCHEMEDELIM = this.delims.scheme;
const __INDEXSCHEME = (path ? path.indexOf(__SCHEMEDELIM) : -1);
return ((~ __INDEXSCHEME) ? path.substring(0, __INDEXSCHEME) : undefined);
},
'stripSchemePrefix' : function(path = undefined) {
const __SCHEMEDELIM = this.delims.scheme;
const __INDEXSCHEME = (path ? path.indexOf(__SCHEMEDELIM) : -1);
return ((~ __INDEXSCHEME) ? path.substring(__INDEXSCHEME + __INDEXSCHEME.length) : path);
},
'getNodeSuffix' : function(path = undefined) {
const __NODEDELIM = this.delims.node;
const __INDEXNODE = (path ? path.lastIndexOf(__NODEDELIM) : -1);
return ((~ __INDEXNODE) ? path.substring(__INDEXNODE + __NODEDELIM.length) : undefined);
},
'stripNodeSuffix' : function(path = undefined) {
const __NODEDELIM = this.delims.node;
const __INDEXNODE = (path ? path.lastIndexOf(__NODEDELIM) : -1);
return ((~ __INDEXNODE) ? path.substring(0, __INDEXNODE) : path);
},
'getQueryString' : function(path = undefined) {
const __QUERYDELIM = this.delims.query;
const __PATH = this.stripNodeSuffix(path);
const __INDEXQUERY = (__PATH ? __PATH.indexOf(__QUERYDELIM) : -1);
return ((~ __INDEXQUERY) ? __PATH.substring(__INDEXQUERY + __QUERYDELIM.length) : undefined);
},
'stripQueryString' : function(path = undefined) {
const __QUERYDELIM = this.delims.query;
const __INDEXQUERY = (path ? path.indexOf(__QUERYDELIM) : -1);
return ((~ __INDEXQUERY) ? path.substring(0, __INDEXQUERY) : path);
},
'formatParams' : function(params, formatFun, delim = ' ', assign = '=') {
const __PARAMS = [];
for (let param in params) {
__PARAMS.push(param + assign + formatFun(params[param]));
}
return __PARAMS.join(delim);
},
'parseParams' : function(params, parseFun, delim = ' ', assign = '=') {
const __RET = { };
if (params) {
const __PARAMS = params.split(delim);
for (let index = 0; index < __PARAMS.length; index++) {
const __PARAM = __PARAMS[index];
if (__PARAM) {
const __INDEX = __PARAM.indexOf(assign);
const __KEY = ((~ __INDEX) ? __PARAM.substring(0, __INDEX) : __PARAM);
const __VAL = ((~ __INDEX) ? parseFun(__PARAM.substring(__INDEX + assign.length)) : true);
__RET[__KEY] = __VAL;
}
}
}
return __RET;
},
'rawValue' : function(value) {
return value;
},
'parseValue' : function(value) {
const __VALUE = Number(value);
if (__VALUE == value) { // schwacher Vergleich true, also Number
return __VALUE;
} else {
const __LOWER = (value ? value.toLowerCase() : undefined);
if ((__LOWER === 'true') || (__LOWER === 'false')) {
return (value === 'true');
}
}
return value;
},
'getQuery' : function(delims = { }) {
const __QRYSEP = ((delims.qrySep !== undefined) ? delims.qrySep : this.delims.qrySep);
const __QRYASS = ((delims.qryAss !== undefined) ? delims.qryAss : this.delims.qryAss);
return this.formatParams(this.query, this.rawValue, __QRYSEP, __QRYASS);
},
'parseQuery' : function(path = undefined, delims = { }) {
const __QRYSEP = ((delims.qrySep !== undefined) ? delims.qrySep : this.delims.qrySep);
const __QRYASS = ((delims.qryAss !== undefined) ? delims.qryAss : this.delims.qryAss);
return this.parseParams(path, this.parseValue, __QRYSEP, __QRYASS);
},
'setQuery' : function(query) {
this.query = query;
},
'setQueryPar' : function(key, value) {
this.query[key] = value;
},
'getQueryPar' : function(key) {
return this.query[key];
},
'getPath' : function(dirs = undefined, delims = undefined) {
const __DELIMS = new UriDelims(delims);
const __SCHEMEDELIM = ((__DELIMS.scheme !== undefined) ? __DELIMS.scheme : this.delims.scheme);
const __HOSTDELIM = ((__DELIMS.host !== undefined) ? __DELIMS.host : this.delims.host);
const __PORTDELIM = ((__DELIMS.port !== undefined) ? __DELIMS.port : this.delims.port);
const __QUERYDELIM = ((__DELIMS.query !== undefined) ? __DELIMS.query : this.delims.query);
const __NODEDELIM = ((__DELIMS.node !== undefined) ? __DELIMS.node : this.delims.node);
const __SCHEMENAME = this.scheme;
const __SCHEME = (__SCHEMENAME ? __SCHEMENAME + __SCHEMEDELIM : "");
const __HOSTNAME = this.host;
const __HOST = (__HOSTNAME ? __HOSTDELIM + __HOSTNAME : "");
const __PORTNR = this.port;
const __PORT = ((__HOSTNAME && __PORTNR) ? __PORTDELIM + __PORTNR : "");
const __QUERYSTR = this.getQuery();
const __QUERY = (__QUERYSTR ? __QUERYDELIM + __QUERYSTR : "");
const __NODENAME = this.node;
const __NODE = (__NODENAME ? __NODEDELIM + __NODENAME : "");
return __SCHEME + __HOST + __PORT + Path.prototype.getPath.call(this, dirs, delims) + __QUERY + __NODE;
},
'getDirs' : function(path = undefined, delims = undefined) {
const __PATH = this.getServerPath(path);
return Path.prototype.getDirs.call(this, __PATH);
}
});
// ==================== Ende Abschnitt fuer Klasse URI ====================
// ==================== Abschnitt fuer Klasse Directory ====================
// Basisklasse fuer eine Verzeichnisstruktur
// homePath: Absoluter Startpfad als String
// delims: Objekt mit Trennern und Symbolen als Properties (oder Delims-Objekt)
// 'delim': Trennzeichen zwischen zwei Ebenen
// 'back': Name des relativen Vaterverzeichnisses
// 'root': Kennung vor dem ersten Trenner am Anfang eines absoluten Pfads
// 'home': Kennung vor dem ersten Trenner am Anfang eines Pfads relativ zu Home
function Directory(homePath, delims) {
'use strict';
Path.call(this, homePath, delims);
}
Class.define(Directory, Path, {
'chDir' : function(subDir = undefined) {
if (subDir === undefined) {
this.root();
} else if ((typeof subDir) === 'object') {
for (let sub of subDir) {
this.chDir(sub);
}
} else {
if (subDir === this.delims.home) {
this.home();
} else if (subDir === this.delims.back) {
this.up();
} else {
this.down(subDir);
}
}
},
'pwd' : function() {
return this.getPath();
}
});
// ==================== Ende Abschnitt fuer Klasse Directory ====================
// ==================== Abschnitt fuer Klasse ObjRef ====================
// Basisklasse fuer eine Objekt-Referenz
function ObjRef(rootObj) {
'use strict';
Directory.call(this, undefined, new Delims('/', "..", '/', '~'));
this.setConst('rootObj', rootObj); // Wichtig: Verweis nicht verfolgen! Gefahr durch Zyklen!
}
Class.define(ObjRef, Directory, {
'valueOf' : function() {
let ret = this.rootObj;
for (let name of this.dirs) {
if (ret === undefined) {
break;
}
ret = ret[name];
}
return ret;
}
});
// ==================== Ende Abschnitt fuer Klasse ObjRef ====================
// ==================== Abschnitt fuer diverse Utilities ====================
// Gibt einen Wert zurueck. Ist dieser nicht definiert oder null, wird ein Alternativwert geliefert
// value: Ein Wert. Ist dieser nicht undefined oder null, wird er zurueckgeliefert (oder retValue)
// defValue: Default-Wert fuer den Fall, dass nichts gesetzt ist
// retValue: Falls definiert, Rueckgabe-Wert fuer den Fall, dass value nicht undefined oder null ist
// return Der Wert. Sind weder value noch defValue definiert, dann undefined
function getValue(value, defValue = undefined, retValue = undefined) {
return ((value === undefined) || (value === null)) ? defValue : (retValue === undefined) ? value : retValue;
}
// Gibt einen Wert zurueck. Ist dieser nicht definiert, wird ein Alternativwert geliefert
// value: Ein Wert. Ist dieser definiet und in den Grenzen, wird er zurueckgeliefert
// minValue: Untere Grenze fuer den Wert, falls angegeben
// minValue: Obere Grenze fuer den Wert, falls angegeben
// defValue: Default-Wert fuer den Fall, dass nichts gesetzt ist oder der Wert ausserhalb liegt
// return Der Wert. Sind weder value (in den Grenzen) noch defValue definiert, dann undefined
function getValueIn(value, minValue = undefined, maxValue = undefined, defValue = undefined) {
const __VALUE = getValue(value, defValue);
if ((minValue !== undefined) && (__VALUE < minValue)) {
return defValue;
}
if ((maxValue !== undefined) && (__VALUE > maxValue)) {
return defValue;
}
return __VALUE;
}
// Ermittelt den naechsten Wert aus einer Array-Liste
// arr: Array-Liste mit den moeglichen Werte
// value: Vorher gesetzter Wert
// return Naechster Wert in der Array-Liste
function getNextValue(arr, value) {
const __POS = arr.indexOf(value) + 1;
return arr[getValueIn(__POS, 0, arr.length - 1, 0)];
}
// Gibt ein Produkt zurueck. Ist einer der Multiplikanten nicht definiert, wird ein Alternativwert geliefert
// valueA: Ein Multiplikant. Ist dieser undefined, wird als Produkt defValue zurueckgeliefert
// valueB: Ein Multiplikant. Ist dieser undefined, wird als Produkt defValue zurueckgeliefert
// digits: Anzahl der Stellen nach dem Komma fuer das Produkt (Default: 0)
// defValue: Default-Wert fuer den Fall, dass ein Multiplikant nicht gesetzt ist (Default: NaN)
// return Das Produkt auf digits Stellen genau. Ist dieses nicht definiert, dann defValue
function getMulValue(valueA, valueB, digits = 0, defValue = NaN) {
let product = defValue;
if ((valueA !== undefined) && (valueB !== undefined)) {
product = parseFloat(valueA) * parseFloat(valueB);
}
if (isNaN(product)) {
product = defValue;
}
return parseFloat(product.toFixed(digits));
}
// Gibt eine Ordinalzahl zur uebergebenen Zahl zurueck
// value: Eine ganze Zahl
// defValue: Default-Wert fuer den Fall, dass der Wert nicht gesetzt ist (Default: '*')
// return Die Ordinalzahl als String der Form "n." oder defValue, falls nicht angegeben
function getOrdinal(value, defValue = '*') {
return getValue(value, defValue, value + '.');
}
// Hilfsfunktion fuer Array.sort(): Vergleich zweier Zahlen
// valueA: Erster Zahlenwert
// valueB: Zweiter Zahlenwert
// return -1 = kleiner, 0 = gleich, +1 = groesser
function compareNumber(valueA, valueB) {
return +(valueA > valueB) || (+(valueA === valueB) - 1);
}
// Ueberprueft, ob ein Objekt einer bestimmten Klasse angehoert (ggfs. per Vererbung)
// obj: Ein (generisches) Objekt
// base: Eine Objektklasse (Konstruktor-Funktion)
// return true, wenn der Prototyp rekursiv gefunden werden konnte
function instanceOf(obj, base) {
while (obj !== null) {
if (obj === base.prototype) {
return true;
}
if ((typeof obj) === 'xml') { // Sonderfall mit Selbstbezug
return (base.prototype === XML.prototype);
}
obj = Object.getPrototypeOf(obj);
}
return false;
}
// Liefert alle Basisklassen des Objekts (inkl. Vererbung)
// obj: Ein (generisches) Objekt
// return true, wenn der Prototyp rekursiv gefunden werden konnte
function getPrototypes(obj) {
let ret = [];
while (obj !== null) {
const __PROTO = Object.getPrototypeOf(obj);
ret.push(__PROTO);
if ((typeof obj) === 'xml') { // Sonderfall mit Selbstbezug
break;
}
obj = __PROTO;
}
return ret;
}
// Liefert alle Attribute/Properties des Objekts (inkl. Vererbung)
// obj: Ein (generisches) Objekt
// return Array von Items (Property-Namen)
function getAllProperties(obj) {
let ret = [];
for (let o = obj; o !== null; o = Object.getPrototypeOf(o)) {
ret = ret.concat(Object.getOwnPropertyNames(o));
}
return ret;
}
// Ueberpruefung, ob ein Item aktiv ist oder nicht
// item: Name des betroffenen Items
// inList: Checkliste der inkludierten Items (Positivliste, true fuer aktiv)
// exList: Checkliste der exkludierten Items (Negativliste, true fuer inaktiv)
// return Angabe, ob das Item aktiv ist
function checkItem(item, inList = undefined, exList = undefined) {
let active = true;
if (inList) {
active = (inList[item] === true); // gesetzt und true
}
if (exList) {
if (exList[item] === true) { // gesetzt und true
active = false; // NICHT anzeigen
}
}
return active;
}
// Fuegt Properties zu einem Objekt hinzu, die in einem zweiten stehen. Doppelte Werte werden ueberschrieben
// data: Objekt, dem Daten hinzugefuegt werden
// addData: Objekt, das zusaetzliche Properties enthaelt
// addList: Checkliste der zu setzenden Items (true fuer kopieren), falls angegeben
// ignList: Checkliste der ignorierten Items (true fuer auslassen), falls angegeben
// return Das gemergete Objekt mit allen Properties
function addProps(data, addData, addList = undefined, ignList = undefined) {
for (let item in getValue(addData, { })) {
if (checkItem(item, addList, ignList)) {