-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
106 lines (100 loc) · 3.25 KB
/
Copy pathindex.js
File metadata and controls
106 lines (100 loc) · 3.25 KB
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
console.log('UI populated by index.js')
/* dev
http://localhost:8000/epiverse/#url=https://episphere.github.io/gpt/export.js&ui=chatUI
https://epiverse.github.io/#url=https://episphere.github.io/caterpillar/caterpillar.js&ui=ui
http://localhost:8000/epiverse#url=https://episphere.github.io/caterpillar/caterpillar.js&ui=ui
*/
function deHash(hs){
if(hs.length>0){
if(hs[0]=='#'){
hs=hs.slice(1)
}
}
return hs
}
// default UI, note you can define your own
if(location.hash.length==0){
// location.hash='url=https://episphere.github.io/gpt/export.js&ui=chatUI'
location.hash = JSON.parse(localStorage.epiVerse).hash
}else{
let epiV = JSON.parse(localStorage.epiVerse)
epiV.hash=location.hash
localStorage.epiVerse=JSON.stringify(epiV)
}
(async function(){
let consoleArray = [
{
name:"Simple Chat",
parms: "url=https://episphere.github.io/gpt/export.js&ui=chatUI"
},
{
name:"Caterpillar",
parms: "url=https://episphere.github.io/caterpillar/caterpillar.js&ui=ui"
},
{
name:"something else",
parms: deHash(location.hash)
}
];
if(location.hash.length<2){
location.hash=consoleArray[0].parms
}
// get parms from location
let parms={};
(location.search+location.hash)
.split(/[&?#]/g)
.forEach(av=>{
console.log('av:',av);
if(av.match('=')){
av=av.split('=')
parms[av[0]]=av[1]
}
})
console.log('parms:',parms)
// open UI in the default div
let div = document.body.querySelector('#epiVerseDiv');
div.onresize=function(){
return Math.min(div.clientWidth,200)
}
// turn this into a whitelist
if((!!parms.url.match(/^https:\/\/episphere.github.io/)||(!!parms.url.match(/^http:\/\/localhost:8000/)))){
(await import(parms.url))[parms.ui](div)
// select function
// console
let consoleArray = [
{
name:"Simple Chat",
parms: "url=https://episphere.github.io/gpt/export.js&ui=chatUI"
},
{
name:"Caterpillar",
parms: "url=https://episphere.github.io/caterpillar/caterpillar.js&ui=ui"
},
{
name:"something else",
parms: deHash(location.hash)
}
];
let selConsole = document.getElementById('selConsole')
consoleArray.forEach(c=>{
let opt = document.createElement('option')
opt.textContent=opt.value=c.name
selConsole.appendChild(opt)
})
selConsole.onchange=function(evt){
location.hash = consoleArray.filter(c=>(c.name==selConsole.value))[0].parms
location.reload()
}
// make sure hash matches
let epiV=JSON.parse(localStorage.epiVerse)
epiV.hash=deHash(epiV.hash)
try{
document.getElementById('selConsole').value=consoleArray.filter(c=>c.parms==epiV.hash)[0].name
}catch(err){
document.getElementById('selConsole').value='something else'
}
//document.getElementById('selConsole').value=consoleArray.filter(c=>c.parms==epiV.hash)[0].name
}else{
alert(`origin not allowed: ${location.origin+location.pathname}`)
}
})()