-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgloe.js
154 lines (152 loc) · 6.08 KB
/
gloe.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
if (window.gloe) { console.error("Gloe already initialized in this environment!"); } else {
const gloeStyleElement = document.createElement('style');
gloeStyleElement.innerHTML = `@import url("https://rsms.me/inter/inter.css");
@import url("https://legacy.klash.dev/legacy.css");
.gloe-window {
width: 400px;
z-index: 99999;
font-family: InterVariable, Inter;
height: 200px;
position: fixed;
color: white;
top: 10px;
left: 10px;
background: #0000009f;
backdrop-filter: blur(40px);
border: 2px solid #00000050;
border-radius: 6px;
}
.gloe-topbar {
width: 100%;
height: 35px;
border-bottom: 2px solid #ffffff30;
background: #1118;
display: flex;
align-items: center;
padding: 0 5px;
font-family: KlashLegacy;
box-sizing: border-box;
user-select: none;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.gloe-title {
width: 70%;
height: 100%;
display: flex;
align-items: center;
}
.gloe-buttons {
width: 30%;
display: flex;
align-items: center;
justify-content: flex-end;
}
.gloe-button {
display: flex;
align-items: center;
justify-content: center;
width: 25px;
height: 25px;
background: #1113;
border: 2px solid #ffffff60;
border-radius: 6px;
}
.gloe-button:hover {
background: #ffffff18;
}
.gloe-content {
height: calc(100% - 35px);
border-radius: 4px;
overflow-y: scroll;
scrollbar-color: #1115 transparent;
scrollbar-width: thin;
margin: 0px 3px;
box-sizing: border-box;
}
.gloe-content button, .gloe-content input {
display: flex;
align-items: center;
justify-content: center;
height: 25px;
width: auto;
padding: 0 2px;
flex-direction: row;
gap: 2px;
background: #1113;
border: 2px solid #ffffff60;
border-radius: 6px;
}
.gloe-content button:focus-within, .gloe-content input:focus-within {
outline: none;
}`;
document.body.insertAdjacentElement('beforeend', gloeStyleElement);
window.gloe = {
_draggable(windowElement, headerElement) {
let isDragging = false, offsetX = 0, offsetY = 0;
headerElement.addEventListener("mousedown", (e) => {
isDragging = true;
offsetX = e.clientX - windowElement.offsetLeft;
offsetY = e.clientY - windowElement.offsetTop;
});
document.addEventListener("mousemove", (e) => {
if (!isDragging) return;
windowElement.style.left = `${Math.min(
Math.max(e.clientX - offsetX, -windowElement.offsetWidth / 2),
window.innerWidth - windowElement.offsetWidth / 2
)}px`;
windowElement.style.top = `${Math.min(
Math.max(e.clientY - offsetY, -windowElement.offsetHeight / 2),
window.innerHeight - windowElement.offsetHeight / 2
)}px`;
});
document.addEventListener("mouseup", () => (isDragging = false));
},
clickFor(query, callback) {document.querySelector(query).addEventListener('click', callback)},
loadGoogleFont(fonts){document.head.appendChild(Object.assign(document.createElement("link"), { rel: "stylesheet", href: `https://fonts.googleapis.com/css2?${fonts.map(f => `family=${f.name.replace(/\s+/g, '+')}:wght@${f.weights.join(';')}`).join('&')}&display=swap` }));},
create(props) {
const { id, title, content, onCreated } = props;
const windowElement = document.createElement("div");
windowElement.className = "gloe-window";
windowElement.id = id || `gloewindow-${Math.floor(Date.now() * Math.random())}`;
windowElement.style.position = "fixed";
const topbar = document.createElement("div");
topbar.className = "gloe-topbar";
const titleSpan = document.createElement("span");
titleSpan.className = "gloe-title";
titleSpan.textContent = title || "Untitled";
topbar.appendChild(titleSpan);
const buttonsDiv = document.createElement("div");
buttonsDiv.className = "gloe-buttons";
const button = document.createElement("button");
button.className = "gloe-button";
const buttonIcon = document.createElement("img");
buttonIcon.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAZhJREFUOE9VU+magyAMnLDv5oX7tMtR7bOZ2S8QrPVHKxgmcwRhfyAQEEAIIgBgP7a2fQjbggLoZcVeT0BUyWVdANoKOI+znemnxfcFQrataZooYs2IVz1sXzkvK87ztOp+8NHVVu0xIvZPAYWYp4n19TIAcl5mvM+3XNfFYBqsgzMywEao0VfWWhHjLgbwMoC7A4CUM+O2IsiPGMXx0UhRlaVUxD1+JLrKG8O6pL/MLW5uZjeDF1lqQYzRyA27GitvMlzrWtNf4hZjA6GSJRfE39hrm0cjJWk+P3caqhXllLhtG3It2PddPEmv7X73OJ8AA8vDGCClFMR9/47XqXwZcsdFMzRxWzdI+GlRNxlm4FdHZ9Cn0MUByDlxXbsHXa9AebFkS2F3/s/xeAjMOXNtUYaHPE9DlTm7J7cNSs7rgvdxSEp+OIRb2hgivxjgpZQQZJ4n1jbKaqO84H2exuO+RY9gXcQQ2b/co6yqfpn6VJzH0V863LiIt2A72OdBUI9qDGzox3QIjN7nUg0L+wRZlVL7S2sj+Ad0mAr3VMR7YgAAAABJRU5ErkJggg==";
buttonIcon.addEventListener('click', (e) => {
windowElement.remove();
});
button.appendChild(buttonIcon);
buttonsDiv.appendChild(button);
topbar.appendChild(buttonsDiv);
windowElement.appendChild(topbar);
const contentDiv = document.createElement("div");
contentDiv.className = "gloe-content";
if (content) {
if (typeof content === "string") {
contentDiv.innerHTML = content;
} else if (content instanceof HTMLElement) {
contentDiv.appendChild(content);
}
} else {
contentDiv.textContent = "No content provided for Gloe";
}
windowElement.appendChild(contentDiv);
document.body.appendChild(windowElement);
this._draggable(windowElement, topbar);
if (onCreated && typeof onCreated === "function") {
onCreated(windowElement);
}
return windowElement;
}
}
};