Skip to content

Commit f4915fe

Browse files
Add files via upload
1 parent 3ced2f0 commit f4915fe

File tree

14 files changed

+464
-132
lines changed

14 files changed

+464
-132
lines changed

WebServerAI/assets/AI/css/webserverai.min.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
--wsa-light-link: #0d0dff;
2222
--wsa-light-scrollbar-bg: #d5d5d5;
2323
--wsa-light-scrollbar-thumb: #c0c0c0;
24+
--wsa-light-mic-enabled: #ff0000;
2425

2526
--wsa-dark-bg: #000;
2627
--wsa-dark-color: #dedede;
@@ -46,6 +47,7 @@
4647
--wsa-dark-scrollbar-thumb: #3c3d3b;
4748
--wsa-dark-toggleBtn-bg:rgba(71, 71, 71, 0.65);
4849
--wsa-dark-toggleBtn-color: rgb(255,255,255);
50+
--wsa-dark-mic-enabled: #c91414;
4951

5052
--wsa-box-width: 60%;
5153
--wsa-box-height: 280px;
@@ -446,12 +448,28 @@
446448
height: 64px;
447449
border-radius: 50%;
448450
}
449-
450451
.wsa .wsa-txt{
451452
width: 410px;
452453
overflow: auto;
453454
}
454455

456+
.wsa[wsa-theme="light"] .wsa-mic:not(.wsa-mic-muted){
457+
background-color: var(--wsa-light-mic-enabled);
458+
animation: flashingMic 0.7s linear alternate infinite;
459+
}
460+
.wsa[wsa-theme="dark"] .wsa-mic:not(.wsa-mic-muted){
461+
background-color: var(--wsa-dark-mic-enabled);
462+
animation: flashingMic 0.7s linear alternate infinite;
463+
}
464+
@keyframes flashingMic {
465+
from{
466+
opacity: 1;
467+
}
468+
to{
469+
opacity: 0.5;
470+
}
471+
}
472+
455473
/*[wsa-elemfocus]{
456474
border: 3px dotted var(--wsa-element-focus);
457475
padding: .8rem;

WebServerAI/assets/AI/js/components/Events.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var responce;
2+
import { filterHTML } from "./security.js";
3+
import { IS_ENABLED } from "./utils.js";
24
class Events{
35
constructor(){
46

@@ -66,5 +68,27 @@ class Events{
6668
req.send();
6769
return responce;
6870
}
71+
/**
72+
* Triggers on users input from textarea
73+
* @param {Function} callback The function that will activate on submit
74+
* @returns {String} The Users input
75+
*/
76+
submit(callback){
77+
if(IS_ENABLED()){
78+
const txt = document.querySelector('.wsa-userinput'),
79+
submitbtn = document.querySelector('.wsa-editor-send');
80+
txt.addEventListener('keydown', (e)=>{
81+
let key = e.keyCode || e.which;
82+
if(key===13){
83+
e.preventDefault();
84+
callback(filterHTML(txt.value));
85+
}
86+
});
87+
submitbtn.addEventListener('click',(e)=>{
88+
e.preventDefault();
89+
callback(filterHTML(txt.value));
90+
});
91+
}
92+
}
6993
}
7094
export default Events;

WebServerAI/assets/AI/js/components/Learner.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Listener{
112112
* @param {boolean} [rawCode=false] Returns raw HTML
113113
* @returns {Array<boolean,string>|Boolean} Returns information on success
114114
*/
115-
render(AICode,rawCode=false){
115+
render(AICode){
116116
this.lineCode = [];
117117
this.endedElem = [];
118118
this.holder = -1;
@@ -596,7 +596,7 @@ class Listener{
596596
break;
597597
case 'list':
598598
value.split(/(?<!\\),/).forEach((items)=>{
599-
this.lineCode[this.holder].html = (this.lineCode[this.holder].html ? this.lineCode[this.holder].html + '<li>'+items.replace(/\\,/g,',')+'</li>' : '<li>'+items.replace(/\\,/g,',')+'</li>');
599+
this.lineCode[this.holder].html = (this.lineCode[this.holder].html ? this.lineCode[this.holder].html + '<li>'+items.replace(/\\,/g,',').replace(/^ /g,'')+'</li>' : '<li>'+items.replace(/\\,/g,',').replace(/^ /g,'')+'</li>');
600600
});
601601
break;
602602

@@ -769,7 +769,6 @@ class Listener{
769769
elem.style.fontWeight = (this.lineCode[i].styles.fontWeight ? this.lineCode[i].styles.fontWeight : '');
770770
elem.style.fontStyle = (this.lineCode[i].styles.fontStyle ? this.lineCode[i].styles.fontStyle : '');
771771
elem.style.textDecoration = (this.lineCode[this.holder]&&this.lineCode[this.holder].styles.textDecoration ? this.lineCode[this.holder].styles.textDecoration : '');
772-
if(!rawCode){
773772
if(this.lineCode[i].location){
774773
if(document.querySelector(this.lineCode[i].location).tagName.toLocaleLowerCase()==='body'){
775774
document.body.insertBefore(elem,document.body.children[this.placeOver]);
@@ -783,10 +782,7 @@ class Listener{
783782
document.body.insertBefore(elem,document.body.children[this.placeOver]);
784783
this.placeOver+=1;
785784
}
786-
}
787-
}else{
788-
this.endedElem.push(elem.outerHTML);
789-
}
785+
}
790786
}
791787
(this.buildEvent!==null ? window.dispatchEvent(this.buildEvent) : ''); this.buildEvent=null;
792788
document.querySelectorAll('code').forEach((e)=>{

WebServerAI/assets/AI/js/components/security.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,23 @@ filter=(str, removeWords)=>{
354354
return str;
355355
}
356356

357+
/**
358+
* Filters out special characters
359+
* @param {String} str String to filter
360+
* @returns {String} Filtered string
361+
*/
362+
function filterHTML(str){
363+
var lt = /</g,
364+
gt = />/g,
365+
ap = /'/g,
366+
ic = /"/g;
367+
return str.toString().replace(lt, "&lt;").replace(gt, "&gt;").replace(ap, "&#39;").replace(ic, "&#34;");
368+
}
369+
357370
export {validate,
358371
sanitize,
359372
filter,
373+
filterHTML,
360374
FILTER_VALIDATE_INT,
361375
FILTER_VALDATE_BOOLEAN,
362376
FILTER_VALIDATE_FLOAT,
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
var session = {
2+
/**
3+
* Saves data as a session storage
4+
* @param {String} name Sessions name
5+
* @param {*} data Data to save
6+
*/
7+
save: (name, data)=>{
8+
sessionStorage.setItem(name, data);
9+
},
10+
/**
11+
* Returns data from a Session storage
12+
* @param {String} name Sessions name
13+
* @returns {*} Data from the session
14+
*/
15+
load: (name)=>{
16+
return sessionStorage.getItem(name);
17+
},
18+
/**
19+
* Delete item from the Session storage
20+
* @param {String} name Item from Session storage
21+
*/
22+
delete: (name)=>{
23+
sessionStorage.removeItem(name)
24+
}
25+
},
26+
local = {
27+
/**
28+
* Saves data as a Local storage
29+
* @param {String} name Local name
30+
* @param {*} data Data to save
31+
*/
32+
save: (name, data)=>{
33+
localStorage.setItem(name, data);
34+
},
35+
/**
36+
* Returns data from a Local storage
37+
* @param {String} name Local name
38+
* @returns {*} Data from the Local
39+
*/
40+
load: (name)=>{
41+
return localStorage.getItem(name);
42+
},
43+
/**
44+
* Delete item from the Local storage
45+
* @param {String} name Item from Local storage
46+
*/
47+
delete: (name)=>{
48+
localStorage.removeItem(name)
49+
}
50+
},
51+
cookie = {
52+
/**
53+
* Sets a cookie to the browser
54+
* @param {String} name Cookies name
55+
* @param {*} value Value to the cookie
56+
* @param {Number} expire Expire day; Ex: (86400 * 30); // 86400 = 1 day
57+
* @param {String} [path="/"] [Optional] Path to store the cookie
58+
*/
59+
set: (name, value, expire, path='/')=>{
60+
const d = new Date();
61+
d.setTime(d.getTime()+expire);
62+
const expires = "expires="+d.toUTCString();
63+
document.cookie = name+'='+value+';'+expires+';path='+path+';';
64+
},
65+
/**
66+
* Returns the cookies value
67+
* @param {String} cname Cookies name
68+
* @returns {*|Null} Cookies value
69+
*/
70+
get: (cname)=>{
71+
let name = cname + "=";
72+
let decodedCookie = decodeURIComponent(document.cookie);
73+
let ca = decodedCookie.split(';');
74+
for(let i = 0; i <ca.length; i++) {
75+
let c = ca[i];
76+
while (c.charAt(0) == ' ') {
77+
c = c.substring(1);
78+
}
79+
if (c.indexOf(name) == 0) {
80+
return c.substring(name.length, c.length);
81+
}
82+
}
83+
return null;
84+
},
85+
/**
86+
* Checks if the cookie exists
87+
* @param {String} cname Cookie to check for
88+
* @returns {Boolean} If TRUE, the cookie exists, else FALSE
89+
*/
90+
check: (cname)=>{
91+
let username = getCookie(cname);
92+
if (username != "") return true;
93+
else return false;
94+
},
95+
/**
96+
* Removes the cookie from thew browser
97+
* @param {String} cname Cookies name
98+
* @param {String} [cpath="/"] Cookies path
99+
*/
100+
delete: (cname, cpath='/')=>{
101+
const d = new Date();
102+
d.setTime(d.getTime() - 3600);
103+
document.cookie = cname+'='+';expires='+d.toUTCString()+';path='+cpath+';';
104+
}
105+
}
106+
107+
export {session, local, cookie};

WebServerAI/assets/AI/js/components/utils.js

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function keyboardFocusable(elem){
109109
return false;
110110

111111
}
112+
113+
112114
const matches = {
113115
'>':'<',
114116
'<':'>',
@@ -270,13 +272,62 @@ function isWSActive(){
270272
return (document.documentElement.hasAttribute('wsa-active') ? true : false);
271273
}
272274

275+
/**
276+
* Decode HTML to encoded
277+
* @param {Array<String>|String} $items
278+
* @returns {Array<String>|String} Returns the encoded HTML
279+
*/
280+
function HTMLEncoder($items){
281+
if(Array.isArray($items)){
282+
return $items.map((e)=>{
283+
return e.replace(/</g,'&lt;').replace(/>/g,'&gt;');
284+
});
285+
}else{
286+
return $items.replace(/</g,'&lt;').replace(/>/g,'&gt;');
287+
}
288+
}
289+
/**
290+
* Encoded HTML to decoded
291+
* @param {Array<String>|String} $items
292+
* @returns {Array<String>|String} Returns the decoded HTML
293+
*/
294+
function HTMLDecoder($items){
295+
if(Array.isArray($items)){
296+
return $items.map((e)=>{
297+
return e.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
298+
});
299+
}else{
300+
return $items.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
301+
}
302+
}
303+
/**
304+
* Merges array items with a certain character into 1 item array
305+
* @param {Array} Arr Array to merge
306+
* @param {String} mergeWith A character to merge items with
307+
* @returns {Array} Merges into 1 item array
308+
*/
309+
function merge(Arr, mergeWith=''){
310+
return [Arr.join(mergeWith)];
311+
}
312+
313+
/**
314+
* Generate a unique id
315+
*
316+
* @param {string} [prefix=''] Prefix to the start of the ID
317+
* @param {boolean} [more_entropy=false] add more to the list
318+
* @returns {string}
319+
*/
320+
function uniqid(prefix='', more_entropy=false){
321+
return prefix+(Date.now().toString(36) + Math.random().toString(36).substr(2)).substr(0,(more_entropy ? 23 : 13));
322+
}
323+
273324
const VIDEO_PATH = window.location.origin+'/WebServerAI/assets/AI/videos',
274325
AUDIO_PATH = window.location.origin+'/WebServerAI/assets/AI/audios',
275326
IMAGE_PATH = window.location.origin+'/WebServerAI/assets/AI/images',
276327
SUBTITLE_PATH = window.location.origin+'/WebServerAI/assets/AI/subtitles',
277328
DS = '/',
278-
ORGIN = window.location.origin;
279-
329+
ORGIN = window.location.origin,
330+
IS_ENABLED = ()=>{return document.documentElement.hasAttribute('wsa-active')};
280331
export {
281332
rgbaToHex,
282333
calculateContrastRatio,
@@ -286,6 +337,11 @@ export {
286337
isScrollable,
287338
getInfo,
288339
isWSActive,
340+
HTMLEncoder,
341+
HTMLDecoder,
342+
merge,
343+
uniqid,
344+
IS_ENABLED,
289345
//CONST
290346
VIDEO_PATH,
291347
AUDIO_PATH,

0 commit comments

Comments
 (0)