-
Notifications
You must be signed in to change notification settings - Fork 3
/
DirecJS.js
176 lines (159 loc) · 4.45 KB
/
DirecJS.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
/*
* DirecJS Version 2.0 (Always Updating Latest on Github ) - First and Last Version name
*
* Website :- https://sh20raj.github.io/DirecJS/
*
*
*/
//functions
//Add this Function to use $ instead of dj..... let $ = (a) => dj(a);
var sd = document;
let dj = (a) => {
s = sd.querySelectorAll(a);
s.ready = (a) => {
s.onload = a;
return s
};
s.css = (a, b) => {
if (b) {
for(var i = 0; i < s.length ;i++){s[i].style[a] = b}
} else {
for (let key in a) {
var i = 0;
while( i < s.length ){ s[i].style[key] = a[key];i++ }
}
}
return s
}
s.hide = (a) => {
for(var i = 0; i <s.length ;i++){s[i].style.display = 'none'; }
return s
};
s.alert = (b) => {
if (!b) {
b = 'innerHTML'
}
for(var i = 0; i <s.length ;i++){alert(s[i][b]); }
return s
};
s.html = (a) => {
if (a) {
for(var i = 0; i <s.length ;i++){s[i].innerHTML = a; }
return s
}
var tp = "";
for(var i = 0; i <s.length ;i++){tp += s[i].innerHTML }
return tp ;
};
s.text = (a) => {
if (a) {
for(var i = 0; i <s.length ;i++){s[i].innerText = a; }
return s
}
var tp = "";
for(var i = 0; i <s.length ;i++){tp += s[i].innerText }
return tp ;
};
s.val = (a) => {
if (a) {
for(var i = 0; i <s.length ;i++){s[i].value = a; }
return s
}
var tp = "";
for(var i = 0; i <s.length ;i++){tp += s[i].innerText }
return tp ;
};
s.append = (b, c) => {
append(a, b, c);
return s
};
s.prepend = (b, c) => {
prepend(a, b, c);
return s
};
s.appendTo = (b,c) => {
for(var i = 0; i <s.length ;i++){d = s[i].innerHTML ; }
append(b, d, c);
return s
};
return s;
}
let $ = (a) => dj(a);
let get = {};
function get_(a, b, c) {
var text;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
rpns = this.responseText;
switch (b) {
case 'json':
text = JSON.parse(rpns);
break;
case 'dom':
text = DOMParser(rpns);
break;
default:
text = rpns;
}
}
};
xhttp.open("GET", a, c);
xhttp.send();
return text;
}
get.dom = (a, c) => get_(a, 'dom', c);
get.json = (a, c) => get_(a, 'json', c);
//Basic Functions
let csl = (a) => console.log(a);
//Copy Function
function copy_(a, b, c) {
//Codes
}
//Append Functions
function append(a, b, c) {
if (!c) c = 'Beforeend';
for(var i = 0; i <dj(a).length ;i++){dj(a)[i].insertAdjacentHTML(c, b) }
}
let prepend = (a,b,c) =>{if (!c) c = 'afterBegin';append_(a,b,c)};
function hide(a) {
switch (typeof (a)) {
case 'object':
a.style.display = 'none';
break;
default:
dj(a).style.display = 'none';
break;
}
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
let search = (a,b) => getParameterByName(a,b);
//Maths Functions
function secondsToMinutes(time) {
return Math.floor(time / 60) + ':' + Math.floor(time % 60);
}
//Add Module for Instant importing Things
function add(a) {
switch (a) {
case 'bootstrap':
add.css('https://cdn.jsdelivr.net/gh/twbs/bootstrap/dist/css/bootstrap.min.css');
break;
case 'jquery':
add.js("https://code.jquery.com/jquery-3.5.1.min.js");
break;
case 'prismjs':
add.css('https://cdn.jsdelivr.net/gh/DirecJS/PrismJS@latest/prism.min.css');
add.js("https://cdn.jsdelivr.net/gh/DirecJS/PrismJS@latest/prism.min.js");
break;
}
}
add.css = (a) => append('head', '<link rel="stylesheet" href="' + a + '" />');
add.js = (a) => append('body', '<script src="' + a + '"></script>');