Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
OutRed
GitHub Repository: OutRed/artclass
Path: blob/main/static/js/main.js
595 views
1
const setObj = function(key, obj) {
2
localStorage.setItem(key, JSON.stringify(obj))
3
}
4
const getObj = function(key) {
5
return JSON.parse(localStorage.getItem(key))
6
}
7
8
function loadcustomapp() {
9
if (!getObj("customapps")) {
10
setObj("customapps", [])
11
}
12
var name = prompt("What should this app be named? (required)")
13
var url = prompt("What's this app's url? (required)")
14
var icon = prompt("What's this app's icon? (optional)")
15
var description = prompt("What's this app's description? (optional)")
16
17
18
if (!name || !url) return alert("All required fields must be filled in")
19
if (name.length > 15) return alert("App name is too long (max 30 characters)")
20
21
22
fetch("https://www.uuidtools.com/api/generate/v4")
23
.then(response => response.json())
24
.then(data => {
25
var customapps = getObj("customapps")
26
customapps.push(JSON.parse(`{ "title": "${name} (Custom app)", "url": "${url}", "id": "${data[0]}", "image": "${icon}", "description": "${description}" }`))
27
setObj("customapps", customapps)
28
window.location.href = self.location
29
})
30
31
32
33
34
35
}
36
37
function loadcustomgame() {
38
if (!getObj("customgames")) {
39
setObj("customgames", [])
40
}
41
var name = prompt("What should this game be named? (required)")
42
var url = prompt("What's this game's url? (required)")
43
var icon = prompt("What's this game's icon? (optional)")
44
var description = prompt("What's this game's description? (optional)")
45
46
if (!name || !url) return alert("All required fields must be filled in")
47
if (name.length > 15) return alert("Game name is too long (max 30 characters)")
48
49
50
fetch("https://www.uuidtools.com/api/generate/v4")
51
.then(response => response.json())
52
.then(data => {
53
var customgames = getObj("customapps")
54
customgames.push(JSON.parse(`{ "title": "${name} (Custom game)", "url": "${url}", "id": "${data[0]}", "image": "${icon}", "description": "${description}" }`))
55
setObj("customapps", customgames)
56
window.location.href = self.location
57
})
58
59
60
}
61
62
function debug() {
63
console.log(getObj("customapps"))
64
}
65
66
function clearcustomapps() {
67
setObj("customapps", [])
68
console.log("Removed all custom apps!")
69
}
70
71
function clearcustomgames() {
72
setObj("customgames", [])
73
console.log("Removed all custom games!")
74
}
75
76
// https://www.google.com/search?q=
77
function search(input, template) {
78
try {
79
// input is a valid URL:
80
// eg: https://example.com, https://example.com/test?q=param
81
return new URL(input).toString();
82
} catch (err) {
83
// input was not a valid URL
84
}
85
86
try {
87
// input is a valid URL when http:// is added to the start:
88
// eg: example.com, https://example.com/test?q=param
89
const url = new URL(`http://${input}`);
90
// only if the hostname has a TLD/subdomain
91
if (url.hostname.includes(".")) return url.toString();
92
} catch (err) {
93
// input was not valid URL
94
}
95
96
// input may have been a valid URL, however the hostname was invalid
97
98
// Attempts to convert the input to a fully qualified URL have failed
99
// Treat the input as a search query
100
return `https://www.google.com/search?q=${encodeURIComponent(input)}`
101
}
102
103
const cursor1 = document.createElement("div")
104
const cursor2 = document.createElement("div")
105
106
107
/*
108
<div class="curzr" hidden>
109
<div class="curzr-dot"></div>
110
</div>
111
*/
112
113
class RingDot {
114
constructor() {
115
this.root = document.body
116
this.cursor = document.querySelector(".curzr")
117
this.dot = document.querySelector(".curzr-dot")
118
119
this.pointerX = 0
120
this.pointerY = 0
121
this.cursorSize = 22.8
122
123
this.cursorStyle = {
124
boxSizing: 'border-box',
125
position: 'fixed',
126
display: 'flex',
127
top: `${ this.cursorSize / -2 }px`,
128
left: `${ this.cursorSize / -2 }px`,
129
zIndex: '2147483647',
130
justifyContent: 'center',
131
alignItems: 'center',
132
width: `${ this.cursorSize }px`,
133
height: `${ this.cursorSize }px`,
134
backgroundColor: '#fff0',
135
boxShadow: '0 0 0 1.25px #111920, 0 0 0 2.25px #F2F5F8',
136
borderRadius: '50%',
137
transition: '200ms, transform 66ms',
138
userSelect: 'none',
139
pointerEvents: 'none'
140
}
141
142
this.dotStyle = {
143
boxSizing: 'border-box',
144
position: 'fixed',
145
zIndex: '2147483647',
146
width: '4px',
147
height: '4px',
148
backgroundColor: '#111920',
149
boxShadow: '0 0 0 1px #F2F5F8',
150
borderRadius: '50%',
151
userSelect: 'none',
152
pointerEvents: 'none',
153
}
154
155
this.init(this.cursor, this.cursorStyle)
156
this.init(this.dot, this.dotStyle)
157
}
158
159
init(el, style) {
160
Object.assign(el.style, style)
161
this.cursor.removeAttribute("hidden")
162
163
document.body.style.cursor = 'none'
164
document.body.querySelectorAll("button, label, input, textarea, select, a").forEach((el) => {
165
el.style.cursor = 'inherit'
166
})
167
}
168
169
move(event) {
170
if (event.target.localName === 'button' ||
171
event.target.localName === 'a' ||
172
event.target.onclick !== null ||
173
event.target.className.includes('curzr-hover')) {
174
this.hover(40)
175
} else {
176
this.hoverout()
177
}
178
179
this.pointerX = event.pageX + this.root.getBoundingClientRect().x
180
this.pointerY = event.pageY + this.root.getBoundingClientRect().y
181
182
this.cursor.style.transform = `translate3d(${this.pointerX}px, ${this.pointerY}px, 0)`
183
}
184
185
hover(radius) {
186
this.cursor.style.width = this.cursor.style.height = `${radius}px`
187
this.cursor.style.top = this.cursor.style.left = `${radius / -2}px`
188
}
189
190
hoverout() {
191
this.cursor.style.width = this.cursor.style.height = `${this.cursorSize}px`
192
this.cursor.style.top = this.cursor.style.left = `${this.cursorSize / -2}px`
193
}
194
195
click() {
196
this.cursor.style.transform += ` scale(0.75)`
197
setTimeout(() => {
198
this.cursor.style.transform = this.cursor.style.transform.replace(` scale(0.75)`, '')
199
}, 35)
200
}
201
202
remove() {
203
this.cursor.remove()
204
this.dot.remove()
205
}
206
}
207
208
(() => {
209
const cursor = new RingDot()
210
if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
211
document.onmousemove = function (event) {
212
cursor.move(event)
213
}
214
document.onclick = function () {
215
cursor.click()
216
}
217
} else {
218
cursor.remove()
219
}
220
})()
221
222
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
223
posthog.init('phc_6sob80p3H8f1WYN9PxniGg6HOrjEjCu6spLcawcGohf',{api_host:'/sf'})
224