-
Notifications
You must be signed in to change notification settings - Fork 0
/
gm_grab-links.user.js
2277 lines (2125 loc) · 64 KB
/
gm_grab-links.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 Grab Links
// @fullname Grab Links
// @description Lists all links from one webpage, so you can copy them easily.
// @name:de Link Schnapper
// @fullname:de Link Schnapper
// @description:de Alle Links einer Webseite werden aufgelistet und du kannst sie einfach kopieren.
// @author ollily2907
// @license Apache License, Version 2.0
// @license https://www.apache.org/licenses/LICENSE-2.0.txt
// @icon https://cdn.jsdelivr.net/gh/ollily/gm_grab-links@latest/resource/gl_logo.png
// @homepageURL https://github.com/ollily/gm_grab-links
// @supportURL https://github.com/ollily/gm_grab-links/issues
// @installURL https://greasyfork.org/en/scripts/428402-grab-links
// @updateURL https://greasyfork.org/en/scripts/428402-grab-links
// @downloadURL https://cdn.jsdelivr.net/gh/ollily/gm_grab-links@latest/gm_grab-links.user.js
// @source https://github.com/ollily/gm_grab-links
// @compatible chrome
// @compatible firefox
// @namespace http://userscripts.org/users/ollily
// @run-at document-end
// @version 2.02.006
// @grant unsafeWindow
// @grant GM_addStyle
// @grant GM.addStyle
// @grant GM_getResourceText
// @grant GM.getResourceText
// @include http://gmonkey.*.*/test/*
// @include http://devzone.*.*/test/gm/*
// @include /http(|s)\://(|.+?\.)dailymotion\..+?/.*/
// @include /http(|s)\://(|.+?\.)flickr\..+?/.*/
// @include /http(|s)\://(|.+?\.)instagram\..+?/.*/
// @include /http(|s)\://(|.+?\.)metacafe\..+?/.*/
// @include /http(|s)\://(|.+?\.)ok\.ru.+?/.*/
// @include /http(|s)\://(|.+?\.)pinterest\..+?/.*/
// @include /http(|s)\://(|.+?\.)tiktok\..+?/.*/
// @include /http(|s)\://(|.+?\.)tumblr\..+?/.*/
// @include /http(|s)\://(|.+?\.)tumbral\..+?/.*/
// @include /http(|s)\://(|.+?\.)youtube\..+?/.*/
// ==/UserScript==
/*
Changes:
2021-06-19
- update syntax, remove inspection failures
- add jsdoc
2021-06-19
- add wide/small handling of container
- add result line selection
- optimize link caption generation
2021-06-03
- switch to different IDE
- clean code
2014-05-28
- some layout fixes
- overlays the yt header
2013-03-29
- the first 2.x release
- removing JQuery from script
- new color layout
- now search through link and link description / caption
- optional disable new search and search only by url
2013-02-20
- Detecting clipboard support (disabling on new browsers)
2011-12-27
- Version Number changed
- Added Copy to Clipboard Support (if enabled)
2011-12-20
- Added a 'SELECT ALL' Button
- Search result can be displayed as plain text or linked text
2011-02-06
- Added JSDoc / Code cleaning
- Code Testing function
- Layout update
2011-01-22
- Layout update
2010-09-08
- Don't start search, if it's a known site
- Layout update
2010-08-19
- Layout update
- Set automatic filter on favorite sites
- Many Bugfixes
2010-07-24
- Initial Release
*/
//
// Global Code - START
//
// ---------------
// base-core.js - START
// ---------------
// noinspection JSUnusedGlobalSymbols
const CURR_HOST = document.location.host;
let CURR_PORT = document.location.port;
/**
* The URL we are currently running on.
*/
let currSite = CURR_HOST;
if (document.location.port) {
CURR_PORT = ":" + document.location.port;
if (currSite.search(CURR_PORT) === -1) {
currSite += ":" + document.location.port;
}
}
const currPath = document.location.href.substring(document.location.href.indexOf(currSite) + currSite.length);
const bTestMode = false;
const INIT_ONLOAD = true;
// - General DHTML-Lib - Start
// - modified & extended dhtml.js from selfhtml.de
let DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false;
const SHORT_ID = "id";
const ATTR_SEP = ";";
if (document.getElementById) {
DHTML = true;
DOM = true;
} else {
if (document.all) {
DHTML = true;
MSIE4 = true;
} else {
if (document.layers) {
DHTML = true;
NS4 = true;
}
}
}
if (window.opera) {
OP = true;
}
/**
* Shorthand, tries to find one element represented by the identifier in the
* page.
*
* @param identifier -
* the key (id) of the element
* @returns {Object} the found object or null
*/
function gmGetElI(identifier) {
return gmGetEl(SHORT_ID, identifier, null);
}
/**
* Tries to find one element represented by the identifier in the page.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param elementNumber -
* the index (only used for Mode=name, tagname)
* @returns {Object} the found object or null
*/
function gmGetEl(mode, identifier, elementNumber) {
let element, elementList;
if (gmIsObject(identifier)) {
return identifier;
}
if (!elementNumber) {
elementNumber = 0;
}
if (!gmIsInstanceOf(mode, String)) {
if (mode != null) {
alert(mode.id + " " + identifier.constructor);
} else {
alert(null);
}
return null;
}
if (DOM) {
if (mode.toLowerCase() === "id") {
element = document.getElementById(identifier);
return element;
}
if (mode.toLowerCase() === "name") {
elementList = document.getElementsByName(identifier);
element = elementList[elementNumber];
if (!element || element === "undefined") {
element = null;
}
return element;
}
if (mode.toLowerCase() === "tagname") {
elementList = document.getElementsByTagName(identifier);
element = elementList[elementNumber];
return element;
}
return null;
}
if (MSIE4) {
if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") {
element = document.all(identifier);
return element;
}
if (mode.toLowerCase() === "tagname") {
elementList = document.all.tags(identifier);
element = elementList[elementNumber];
return element;
}
return null;
}
if (NS4) {
if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") {
element = document[identifier];
if (!element) {
element = document.anchors[identifier];
}
return element;
}
if (mode.toLowerCase() === "layerindex") {
element = document.layers[identifier];
return element;
}
return null;
}
return null;
}
/**
* Tries to find all elements represented by the identifier in the page.
*
* @param mode
* how the Identifier is interpreted (id, name, tagname)
* @param identifier
* the key (id, name, tagname) of the element
* @returns {Object} returns the found content as array or null
*/
function gmGetElList(mode, identifier) {
if (gmIsObject(identifier)) {
return identifier;
}
if (identifier == null) {
return null;
}
if (DOM) {
if (mode.toLowerCase() === "name") {
return document.getElementsByName(identifier);
}
if (mode.toLowerCase() === "tagname") {
return document.getElementsByTagName(identifier);
}
return null;
}
if (MSIE4) {
if (mode.toLowerCase() === "id" || mode.toLowerCase() === "name") {
return document.all(identifier);
}
if (mode.toLowerCase() === "tagname") {
return document.all.tags(identifier);
}
return null;
}
if (NS4) {
return gmGetEl(mode, identifier);
}
return null;
}
/**
* Shorthand, tries to find an attribute of an element in the page.
*
* @param identifier -
* the key (id) of the element
* @param attributeName -
* the name of the attribute
* @returns {Object} returns the found attribute or false
*/
function gmGetAtI(identifier, attributeName) {
return gmGetAt(SHORT_ID, identifier, null, attributeName);
}
/**
* Tries to find an attribute of an element in the page.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param elementNumber -
* the index (only used for Mode=name, tagname)
* @param attributeName -
* the name of the attribute
* @returns {Object} returns the found attribute or null
*/
function gmGetAt(mode, identifier, elementNumber, attributeName) {
let attribute = null;
const element = gmGetEl(mode, identifier, elementNumber);
if (element) {
if (DOM || MSIE4) {
try {
attribute = element[attributeName];
} catch (e) {
try {
attribute = element.getAttribute(attributeName);
} catch (e2) {
// ignored
}
}
}
if (NS4) {
attribute = element[attributeName];
if (!attribute) {
attribute = null;
}
}
}
return attribute;
}
/**
* Shorthand, tries to find the content of an element in the page.
*
* @param identifier -
* the key (id) of the element
* @returns {Object} returns the found content or null
*/
function gmGetCoI(identifier) {
return gmGetCo(SHORT_ID, identifier, null);
}
/**
* Tries to find the content of an element in the page.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param elementNumber -
* the index (only used for Mode=name, tagname)
* @returns {Object} returns the found content or null
*/
function gmGetCo(mode, identifier, elementNumber) {
let content = null;
const element = gmGetEl(mode, identifier, elementNumber);
if (element) {
if (DOM && element.firstChild) {
if (element.firstChild.nodeType === 3) {
content = element.firstChild.nodeValue;
} else {
content = "";
}
return content;
}
if (MSIE4) {
content = element.innerText;
return content;
}
}
return content;
}
/**
* Shorthand, tries to set the new content to an element in the page.
*
* @param identifier -
* the key (id) of the element
* @param text -
* the new text to set to the element
* @returns {Boolean} TRUE=if set was successfull, else FALSE
*/
function gmSetCoI(identifier, text) {
return gmSetCo(SHORT_ID, identifier, null, text);
}
/**
* Tries to set the new content to an element in the page.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param elementNumber -
* the index (only used for Mode=name, tagname)
* @param text -
* the new text to set to the element
* @returns {Boolean} TRUE=if set was successfull, else FALSE
*/
function gmSetCo(mode, identifier, elementNumber, text) {
const element = gmGetEl(mode, identifier, elementNumber);
if (element) {
if (DOM) {
if (!element.firstChild) {
element.appendChild(document.createTextNode(""));
}
element.firstChild.nodeValue = text;
return true;
}
if (MSIE4) {
element.innerText = text;
return true;
}
if (NS4) {
element.document.open();
element.document.write(text);
element.document.close();
return true;
}
}
return false;
}
// - General DHTML-Lib - End
/**
* Shorthand: Sets a new value for an attribute to an element, any existing
* attribute value is replaced.
*
* @param identifier -
* the key (id) of the element
* @param attributeName -
* the unique name of the attribute
* @param attributeValue -
* the new value for that attribute
* @returns {Boolean} TRUE = the value could be set, else FALSE
*/
function gmSetAtI(identifier, attributeName, attributeValue) {
return gmSetAt(SHORT_ID, identifier, null, attributeName, attributeValue);
}
/**
* Sets a new value for an attribute to an element, any existing attribute value
* is replaced.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param elementNumber
* @param attributeName -
* the unique name of the attribute
* @param attributeValue -
* the new value for that attribute
* @returns {Boolean} TRUE = the value could be set, else FALSE
*/
function gmSetAt(mode, identifier, elementNumber, attributeName, attributeValue) {
//var attribute;
const element = gmGetEl(mode, identifier, elementNumber);
if (element) {
if (DOM || MSIE4) {
try {
element[attributeName] = attributeValue;
} catch (e) {
try {
element.setAttribute(attributeName, attributeValue);
} catch (e2) {
// ignored
}
}
return true;
// return gmGetAt(mode, identifier, elementNumber, attributeName);
}
if (NS4) {
element[attributeName] = attributeValue;
return true;
// return gmGetAt(mode, identifier, elementNumber, attributeName);
}
}
return false;
}
/**
* Adds an additional value for an attribute to an element, the new value is
* appended at the end.
*
* @param mode -
* how the Identifier is interpreted (id, name, tagname)
* @param identifier -
* the key (id, name, tagname) of the element
* @param attributeName -
* the unique name of the attribute
* @param attributeValue -
* the new value for that attribute
* @returns {Boolean} TRUE = the value could be set, else FALSE
*/
function gmAppAt(mode, identifier, attributeName, attributeValue) {
const oldValue = gmGetAt(mode, identifier, attributeName);
const newValue = oldValue + ATTR_SEP + attributeValue;
return gmSetAt(mode, identifier, attributeName, newValue);
}
/**
* Shorthand: Adds an additional value for an attribute to an element, the new
* value is appended at the end.
*
* @param identifier -
* the key (id, name, tagname) of the element
* @param attributeName -
* the unique name of the attribute
* @param attributeValue -
* the new value for that attribute
* @returns {Boolean} TRUE = the value could be set, else FALSE
*/
function gmAppAtI(identifier, attributeName, attributeValue) {
return gmAppAt(SHORT_ID, identifier, attributeName, attributeValue);
}
/**
* Verifies if an instance is an array.
*
* @param obj -
* the instance to test
* @returns {Boolean} TRUE=if instance is an array, else FALSE
*/
function gmIsArray(obj) {
return gmIsInstanceOf(obj, Array);
}
function gmIsFunction(obj) {
return gmIsInstanceOf(obj, Function);
}
function gmIsUndefined(obj) {
return (obj == null ? true : (typeof obj == "undefined"));
}
/**
* Verifies if an instance is an object.
*
* @param obj -
* the instance to test
* @returns {Boolean} TRUE=if instance is an object, else FALSE
*/
function gmIsObject(obj) {
return (obj == null ? false : (typeof obj == "object"));
}
/**
* Tests, if an instanced object is from the requested type.
*
* @param obj -
* an instance of an object (must not be null)
* @param objType -
* a name of a type, if null it will be replaced by "Object"
* @returns {Boolean} TRUE = if the object is from the tested type, else FALSE
*/
function gmIsInstanceOf(obj, objType) {
let isType = false;
if (obj != null) {
if (objType == null) {
objType = "Object";
}
try {
let tObjType = eval(objType);
isType = (obj.constructor === tObjType);
} catch (e) {
// ignore
}
// isType = (typeof obj) == objType;
}
return isType;
}
/**
* Removes all spaces from the left.
*
* @param a -
* the string to trim
* @returns {String} the trimmed string
*/
function ltrim(a) {
let ret = null;
if (a != null) {
ret = String(a);
let pos = 0;
while (a.charAt(pos) === " ") {
pos++;
}
ret = a.substring(pos);
}
return ret;
}
/**
* Removes all spaces from the right.
*
* @param a -
* the string to trim
* @returns {String} the trimmed string
*/
function rtrim(a) {
let ret = null;
if (a != null) {
ret = String(a);
let pos = a.length - 1;
while (a.charAt(pos) === " ") {
pos--;
}
ret = a.substring(0, pos + 1);
}
return ret;
}
/**
* Removes all space from the left and right.
*
* @param a -
* the string to trim
* @returns {String} the trimmed string
*/
function trim(a) {
return ltrim(rtrim(a));
}
function gmCleanText(dirtyText) {
let cleanText = "";
if (gmIsInstanceOf(dirtyText, String)) {
cleanText = dirtyText.replace(/\s\s/g, "").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").replace(/#/g, "");
}
return cleanText;
}
/**
* Extracts a numeric value from a text. Supports only "full" numbers;
*
* @param a
* the text to parse
* @returns {Number} the found numeric value or 0;
*/
function gmToNo(a) {
let numFound = "";
if (isNaN(a)) {
if (a && a.length > 0) {
for (let int = 0; int < a.length; int++) {
const a_ele = a[int];
if (!isNaN(a_ele)) {
numFound += a_ele;
} else {
}
}
}
} else {
numFound = a;
}
let newNum = Number(numFound).valueOf();
if (typeof (newNum) != "number") {
newNum = 0;
}
return newNum;
}
const SORT_NO = 0;
const SORT_DEF = 1;
const SORT_REV = 2;
const SORT_NUM = 3;
/**
* Sorts an array by a specific sort order (alphanumeric).
*
* @param unsortedArray - the aray which should be sorted
* @param sortMode - the sort order or leave null to ignore sorting
* @returns {Array} the sorted array
*/
function gmSortArray(unsortedArray, sortMode) {
const sortedArray = unsortedArray;
if (sortMode == null) {
sortMode = false;
}
if (sortMode === SORT_NUM) {
sortedArray.sort(function (aE, bE) {
return aE - bE;
});
} else if (sortMode === SORT_REV) {
sortedArray.reverse();
} else if (sortMode || sortMode === SORT_DEF) {
sortedArray.sort();
}
return sortedArray;
}
function gmSortObject(unsortedObjects, sortField) {
try {
if (gmIsArray(unsortedObjects)) {
unsortedObjects.sort(function (aElem, bElem) {
const x = aElem[sortField].toLowerCase();
const y = bElem[sortField].toLowerCase();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
return 0;
}
);
}
} catch (ex) {
alert(ex);
}
return unsortedObjects;
}
function gmOnlyUnique(arrArray) {
let arrUnique = [];
if (gmIsArray(arrArray)) {
arrUnique = arrArray.filter(function (value, index, self) {
return self.indexOf(value) === index;
});
}
return arrUnique;
}
/**
* The start point for all gmonkey scripts.
*
* @param e -
* the occuring event
* @returns {Boolean} TRUE = if all handler are succesfull done, else FALSE
*/
function gmAddHandler(e) {
let isDone;
lgm_addKnownSites();
lgm_addStyles();
lgm_addControls();
lgm_addInitAction();
isDone = true;
return isDone;
}
/**
* Now add the event handler.
*/
function gmInitEventHandler() {
if (INIT_ONLOAD) {
window.addEventListener("load", function (e) {
gmAddHandler(e);
});
}
}
// ---------------
// base-core.js - END
// ---------------
// ---------------
// base-object.js - START
// ---------------
// noinspection JSUnresolvedVariable,JSUnresolvedFunction,JSUnusedGlobalSymbols
/**
* Creates an DOM-Object.
*
* @param par - the parent object to create the new object as child
* @param objtyp - the type of the new object (HTML-Tagname)
* @param id - the id and name of the new object
* @returns {Object} the created object or null
*/
function gmCreateObj(par, objtyp, id) {
// var obj = $("<" + objtyp + ">");
let obj = null;
if (objtyp != null && objtyp !== "") {
obj = document.createElement(objtyp);
if (obj) {
if (id != null) {
// obj.attr("id", id);
// obj.attr("name", id);
gmSetAtI(obj, "id", id);
gmSetAtI(obj, "name", id);
}
if (gmIsObject(par)) {
// $(par).append(obj);
par.appendChild(obj);
}
}
}
return obj;
}
/**
* Create common attributes for an DOM-Object. Leave null if not used.
*
* @param obj - the object to create the attributes in it
* @param caption - a text which will be displayed for this object
* @param tit - a W3C-conform title for that DOM
* @param ro - if set != null, the DOM will be readonly
* @param ev_click - a javascript-call for the click-event
* @param ev_focus - a javascript-call for the focus-event
* @param ev_mOver - a javascript-call for the mouseover-event
* @param ev_mOut - a javascript-call for the mouseout-event
* @param ev_dblClick - a javascript-call for the doubleclick-event
* @returns {Object} the object with added attributes FIXME: Check
*/
function gmCreateObjCommon(obj, caption, tit, ro, ev_click, ev_focus, ev_mOver, ev_mOut, ev_dblClick) {
if (obj) {
// obj.attr("title", tit);
gmSetAtI(obj, "title", tit);
if (ro) {
// obj.attr("readonly", "readonly");
gmSetAtI(obj, "readonly", "readonly");
}
if (caption) {
// obj.append(caption);
gmSetCoI(obj, caption);
}
if (ev_click) {
// obj.click(ev_click);
obj.onclick = ev_click;
}
if (ev_dblClick) {
// obj.click(ev_dblClick);
obj.ondblclick = ev_dblClick;
}
if (ev_focus) {
// obj.focus(ev_focus);
obj.onfocus = ev_focus;
}
if (ev_mOver) {
// obj.hover(ev_mOver);
obj.onmouseover = ev_mOver;
}
if (ev_mOut) {
// obj.hover(ev_mOut);
obj.onmouseout = ev_mOut;
}
}
return obj;
}
/**
* Creates a DOM-Button.
*
* @param par - the parent object to create the new object as child
* @param typ - the type of the new object (HTML-Tagname)
* @param id - the id and name of the new object
* @param caption - a text which will be displayed for this object
* @param tit - a W3C-conform title for that DOM
* @param initval - an initial value is set in this input
* @param ev_click - a javascript-call for the click-event
* @returns {Object} the created DOM-Button
*/
function gmCreateButton(par, typ, id, caption, tit, initval, ev_click) {
let obj = gmCreateObj(par, "button", id);
obj = gmCreateObjCommon(obj, caption, tit, null, ev_click);
if (!typ) {
typ = "button";
}
gmSetAtI(obj, "type", typ);
if (initval) {
gmSetAtI(obj, "value", initval);
}
return obj;
}
/**
* Creates a DOM-Link.
*
* @param par - the parent object to create the new object as child
* @param id - the id and name of the new object
* @param href
* @param caption - a text which will be displayed for this object
* @param tit - a W3C-conform title for that DOM
* @param target
* @param ev_click - a javascript-call for the click-event
* @param ev_dblClick - a javascript-call for the doubleclick-event
* @returns {Object} the created DOM-Link
*/
function gmCreateLink(par, id, href, caption, tit, target, ev_click, ev_dblClick) {
let obj = gmCreateObj(par, "a", id);
obj = gmCreateObjCommon(obj, caption, tit, null, ev_click, null, null, null, ev_dblClick);
if (href) {
gmSetAtI(obj, "href", href);
gmSetAtI(obj, "data-href", href);
}
if (target) {
gmSetAtI(obj, "target", target);
}
return obj;
}
/**
* Creates a DOM-Input-Element.
*
* @param par - the parent object to create the new object as child
* @param typ - the type of the new input (Type-Attribute)
* @param id - the id and name of the new object
* @param initval - an initial value is set in this input
* @param tit - a W3C-conform title for that DOM
* @param ro - if set != null, the DOM will be readonly
* @param ev_click - a javascript-call for the click-event
* @param ev_focus - a javascript-call for the focus-event
* @returns {Object} the new DOM-Input
*/
function gmCreateInput(par, typ, id, initval, tit, ro, ev_click, ev_focus) {
let obj = gmCreateObj(par, "input", id);
if (obj) {
obj = gmCreateObjCommon(obj, null, tit, ro, ev_click, ev_focus);
if (!typ) {
typ = "text";
}
gmSetAtI(obj, "type", typ);
if (initval) {
// obj.val(initval);
gmSetAtI(obj, "value", initval);
} else {
// obj.val("");
gmSetAtI(obj, "value", "");
}
}
return obj;
}
/**
* Adds an object as a child node to a parent object or the document body.
*
* @param obj - the object to append at the end of the child list
* @param parent - the parent object to append to, leave null to put it to the
* document-body
* @returns {Boolean} TRUE = the object could be added, else FALSE
*/
function gmAddObj(obj, parent) {
let isSet = false;
if (gmIsObject(obj)) {
if (!parent) {
parent = gmGetEl("tagname", "body");
}
parent.appendChild(obj);
isSet = true;
}
return isSet;
}
/**
* Sets a new value into an object.
*
* @param id - the id of the object
* @param initval - the new value for that element or empty
* @returns {Boolean} TRUE = if the value could be set, else FALSE
*/
function gmSetInput(id, initval) {
let isSet = false;
// var obj = document.getElementById(id);
const obj = gmGetElI(id);
if (obj) {
if (initval) {
// obj.setAttribute("value", initval);
gmSetAtI(obj, "value", initval);
isSet = true;
} else {
// obj.setAttribute("value", "");
gmSetAtI(obj, "value", "");
isSet = true;
}
}
return isSet;
}
/**
* Selects the text in a input element.
*
* @param inputElem - the element containing the text
* @returns {Boolean} TRUE = if the input element could be selected, else FALSE
*/
function gmSelectInput(inputElem) {
let isSet = false;
if (gmIsObject(inputElem)) {
try {
inputElem.select();
isSet = true;
} catch (e) {
}
}
return isSet;
}
/**
* Constants for Selection of Text using IE.
*/
const SELECT_IE = 0;
/**
* Constants for Selection of Text using Gecko Engine.
*/
const SELECT_G = 1;