-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.js
258 lines (235 loc) · 6.89 KB
/
functions.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
import cryptoJs from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
export function setCookie(cname, cvalue) {
localStorage.setItem(cname, cvalue)
}
export function getCookie(cname) {
if (localStorage.getItem(cname) != undefined) {
return localStorage.getItem(cname)
}
return null;
}
export function Regex(text) {
let regex = /\?/;
return regex.test(text)
}
export function delCookie(name) {
localStorage.removeItem(name)
}
export function removeloader() {
document.getElementById("loader").remove();
document.getElementById("wait-connected").remove()
if (localStorage.getItem("state" != "disable")) {
localStorage.setItem("state", "yes")
}
}
export function encrypt(text) {
return cryptoJs.enc.Base64.stringify(cryptoJs.enc.Utf8.parse(text));
};
export function decrypt(data) {
return cryptoJs.enc.Base64.parse(data).toString(cryptoJs.enc.Utf8);
};
export function state() {
if (localStorage.getItem("state") == 'yes') {
localStorage.setItem("state", "no")
} else {
localStorage.setItem("state", "yes")
}
}
export function bip() {
if (localStorage.getItem("state") == 'yes') {
var audio = new Audio('message_recive.mp3');
audio.play();
} else {
console.log("notification disable by user")
}
}
export async function getuser() {
const user = netlifyIdentity.currentUser();
return user
}
export function before(text) {
var split = String(text).split(".")
return split[0]
}
/*
mes time = 1sec
act time = 1min
if mes have more than 365j 6h then
get number of years
else then
if mes have more than 30.46666666666667mon then
get number of month
else then
if mess have more than 1d then
get number of day
else then
if mes have more than 1h then
get number of hours
else then
if mes have more thant 1m then
get number of minutes
else then
if mess have more than 1s then
get number of seconds
else
get number of seconds
*/
/*export var CDate = {
"m": 1000 * 60,
"h": this.m * 60,
"d": this.h * 24,
"y": this.d * 365,
"mt": this.d * 0.03287671232876712,
"ss":"",
"define":(m) => {
this.ss = m
return this.ss
},
"day":() => {
return Math.round(this.ss / this.d)
},
"years":() => {
return Math.round(this.ss / this.y)
},
"minutes":() => {
return Math.round(this.ss / this.m)
},
"hours":() => {
return Math.round(this.ss / this.h)
},
"months":() => {
return Math.round(this.ss / this.mt)
},
"":() => {},
"":() => {},
"":() => {},
"":() => {},
}
*/
export function addYears(date, years) {
const dateCopy = new Date(date);
dateCopy.setFullYear(dateCopy.getFullYear() + years);
return dateCopy;
}
export function message_date(DateNow, dname) {
try {
document.getElementById(`time_${dname}`).dataset.send = DateNow
var dateConvert = new Date(DateNow)
var dateUtc = String(dateConvert).split("GMT")
var dateUtc = dateUtc[0].split(" ")
var dateUtc = [0]
var dateActual = new Date(Date.now())
var dateActualy = addYears(dateActual, 1)
if (dateConvert.getFullYear() == dateActual.getFullYear()) {
if (dateConvert.getMonth() == dateActual.getMonth()) {
if (dateConvert.getDate() == dateActual.getDate()) {
if (dateConvert.getHours() == dateActual.getHours()) {
if (dateConvert.getMinutes() == dateActual.getMinutes()) {
var date = dateActualy.getSeconds() - dateConvert.getSeconds()
var date = before(date) + " Sec ago"
} else {
var date = dateActualy.getMinutes() - dateConvert.getMinutes()
var date = before(date) + " Min ago"
}
} else {
var date = dateActualy.getHours() - dateConvert.getHours()
var date = before(date) + " Hours ago"
}
} else {
var date = dateActualy.getDate() - dateConvert.getDate()
var date = before(date) + " Days ago"
}
} else {
var date = dateActualy.getMonth() - dateConvert.getMonth()
var date = before(date) + " Months ago"
}
} else {
var date = dateActualy.getFullYear() - dateConvert.getFullYear()
var date = before(date) + " Years ago"
}
return date
} catch {
return null
}
}
export function urlify(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function (url) {
return `<a class="link" onclick="Openurl('${url}')">${url}</a>`;
})
}
export function link_render(message) {
return urlify(message)
}
export function textMessage(message) {
const xhr = new XMLHttpRequest();
xhr.open('POST', 'https://vector.profanity.dev', false); // 'false' makes the request synchronous
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({ message }));
var status = JSON.parse(xhr.response)
if (xhr.status >= 200 && xhr.status < 300) {
if (status.isProfanity) {
console.log(status)
var regex = new RegExp(status.flaggedFor, "gi");
return message.replace(regex, match => '*'.repeat(match.length));
}
return message;
} else {
throw new Error(`Request failed with status ${xhr.status}`);
}
}
export function message_render(message, type = "none") {
var messages = (function (t) {
var r = /[^\u0300-\u036F\u0489]+/g;
var unzalgo = function () {
return (t.match(r) || [""]).join("");
};
return unzalgo()
})(message);
if (messages != undefined && messages != "") {
var message_good = messages
} else {
var message_good = message
}
var message_start = message_good.substring(0, 1000);
var message_start = message_start.replaceAll('<','<')
var message_start = message_start.replaceAll('>','>')
if (type == "nop") {
var message_start = textMessage(message_start)
}
if (message_start == "undefined" || message_start == undefined) {
return null;
}
if (type == "none") {
return message_start
} else {
return message_start
}
}
export function markdown_render(message) {
if (message.slice(0,1) == '#') {
return marked.parse(message)
}
return message
}
export function loadScript(file) {
var tag = document.createElement("script");
tag.src = file;
document.getElementById("import").appendChild(tag);
}
export const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, { type: contentType });
return blob;
}