soiz commited on
Commit
e3f24a1
·
verified ·
1 Parent(s): b718b87

Create cl.js

Browse files
Files changed (1) hide show
  1. cl.js +277 -0
cl.js ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function() {
2
+ var s;
3
+ if (!document.querySelector('style.EVALDOTJSSTYLETHING')) {
4
+ s=document.createElement("style");
5
+ s.className="EVALDOTJSSTYLETHING";
6
+ s.innerHTML=`
7
+ evalcontainer {
8
+ display: block;
9
+ position: fixed;
10
+ width: 500px;
11
+ height: 350px;
12
+ background: rgba(0,0,0,0.8);
13
+ top: 0;
14
+ left: 0;
15
+ right: 0;
16
+ margin: 50px auto;
17
+ font-size: 0;
18
+ z-index: 100000;
19
+ cursor: move; /* ドラッグカーソルを追加 */
20
+ }
21
+ evalcontainer > textarea.EVALTEXTAREA {
22
+ width: 500px;
23
+ border: none;
24
+ box-sizing: border-box;
25
+ font-family: monospace;
26
+ font-size: 12px;
27
+ height: 200px;
28
+ padding: 5px;
29
+ resize: none;
30
+ position: absolute;
31
+ bottom: 0;
32
+ background: rgba(0,0,0,0.8);
33
+ color: white;
34
+ }
35
+ evalcontainer > evaloutput {
36
+ display: block;
37
+ width: 500px;
38
+ max-height: 150px;
39
+ font-size: 12px;
40
+ font-family: monospace;
41
+ overflow-y: auto;
42
+ color: white;
43
+ box-sizing: border-box;
44
+ padding: 5px;
45
+ position: absolute;
46
+ bottom: 200px;
47
+ }
48
+ evalcontainer > evaloutput > evaloutputentry {
49
+ display: block;
50
+ white-space: pre;
51
+ }
52
+ evalcontainer > evaloutput > evaloutputentry::before {
53
+ content: ">\\00a0";
54
+ color: rgba(255,255,255,0.5);
55
+ }
56
+ evalcontainer > evaloutput > evaloutputentry.EVALRESULT {
57
+ border-bottom: 1px solid rgba(255,255,255,0.1);
58
+ }
59
+ evalcontainer > evaloutput > evaloutputentry.EVALRESULT::before {
60
+ content: "<\\00a0";
61
+ font-style: normal;
62
+ }
63
+ evalcontainer > evaloutput > evaloutputentry.EVALWARN {
64
+ background: #FFEB3B;
65
+ color: black;
66
+ }
67
+ evalcontainer > evaloutput > evaloutputentry.EVALSTRING {
68
+ color: #FFEB3B;
69
+ }
70
+ evalcontainer > evaloutput > evaloutputentry.EVALNUMBER {
71
+ color: #2196F3;
72
+ }
73
+ evalcontainer > evaloutput > evaloutputentry.EVALFUNCTION {
74
+ font-style: italic;
75
+ }
76
+ evalcontainer > evaloutput > evaloutputentry.EVALUNDEFINED {
77
+ color: #9E9E9E;
78
+ }
79
+ evalcontainer > evaloutput > evaloutputentry.EVALERROR {
80
+ background: #f44336;
81
+ }
82
+ evalcontainer > evaloutput > evaloutputentry.EVALWARN.EVALSTRING {
83
+ color: black;
84
+ }
85
+ .close-button {
86
+ position: absolute;
87
+ top: 5px;
88
+ right: 5px;
89
+ background: rgba(255, 0, 0, 0.8);
90
+ color: white;
91
+ border: none;
92
+ padding: 5px;
93
+ cursor: pointer;
94
+ }
95
+ .draggable-icon {
96
+ position: absolute;
97
+ top: 5px;
98
+ left: 5px;
99
+ font-size: 20px;
100
+ cursor: move; /* ドラッグカーソルを追加 */
101
+ }
102
+ `;
103
+ document.head.appendChild(s);
104
+ }
105
+ if (!document.querySelector('evalcontainer')) {
106
+ s=document.createElement("evalcontainer");
107
+
108
+ // 右上の「×」ボタンを追加
109
+ var closeButton = document.createElement("button");
110
+ closeButton.className = "close-button";
111
+ closeButton.innerText = "×";
112
+ closeButton.onclick = function() {
113
+ evaljs.close();
114
+ };
115
+ s.appendChild(closeButton);
116
+
117
+ // ドラッグアイコンを追加
118
+ var dragIcon = document.createElement("div");
119
+ dragIcon.className = "draggable-icon";
120
+ dragIcon.innerText = "🖱️";
121
+ s.appendChild(dragIcon);
122
+
123
+ var output=document.createElement("evaloutput");
124
+ function createOutputEntry(words) {
125
+ var t=document.createElement("evaloutputentry");
126
+ t.innerHTML=words;
127
+ t.className='EVALLOG';
128
+ output.appendChild(t);
129
+ }
130
+ createOutputEntry('To close this window, do evaljs.close();');
131
+ createOutputEntry('To clear, do evaljs.clear();');
132
+ s.appendChild(output);
133
+
134
+ var textarea=document.createElement("textarea");
135
+ textarea.className='EVALTEXTAREA';
136
+ textarea.focus();
137
+ textarea.onkeypress=e=>{
138
+ if (e.keyCode===13&&!e.shiftKey) {
139
+ var t=document.createElement("evaloutputentry"),
140
+ evaloutput;
141
+ t.textContent=textarea.value;
142
+ output.appendChild(t);
143
+ t=document.createElement("evaloutputentry");
144
+ t.classList.add('EVALRESULT');
145
+ try {
146
+ evaloutput=eval(textarea.value);
147
+ switch (typeof evaloutput) {
148
+ case 'object':
149
+ evaloutput=JSON.stringify(evaloutput);
150
+ t.classList.add('EVALFUNCTION');
151
+ break;
152
+ case 'string':
153
+ evaloutput=`"${evaloutput}"`;
154
+ t.classList.add('EVALSTRING');
155
+ break;
156
+ case 'number':
157
+ case 'boolean':
158
+ t.classList.add('EVALNUMBER');
159
+ break;
160
+ case 'function':
161
+ evaloutput=evaloutput.toString();
162
+ t.classList.add('EVALFUNCTION');
163
+ break;
164
+ case 'undefined':
165
+ t.classList.add('EVALUNDEFINED');
166
+ break;
167
+ case 'symbol':
168
+ evaloutput=evaloutput.toString();
169
+ t.classList.add('EVALSTRING');
170
+ break;
171
+ }
172
+ } catch(e) {
173
+ evaloutput=e;
174
+ t.classList.add('EVALERROR');
175
+ }
176
+ t.textContent=evaloutput+'';
177
+ output.appendChild(t);
178
+ output.scrollTop=output.scrollHeight;
179
+ textarea.value='';
180
+ e.preventDefault();
181
+ return false;
182
+ }
183
+ };
184
+ s.appendChild(textarea);
185
+ document.body.appendChild(s);
186
+ evaljs={
187
+ window:s,
188
+ clear() {
189
+ while (output.hasChildNodes()) output.removeChild(output.lastChild);
190
+ },
191
+ close() {
192
+ document.body.removeChild(this.window);
193
+ }
194
+ };
195
+
196
+ // ドラッグ機能を実装
197
+ let isDragging = false;
198
+ let offsetX, offsetY;
199
+
200
+ dragIcon.onmousedown = function(e) {
201
+ isDragging = true;
202
+ offsetX = e.clientX - s.getBoundingClientRect().left;
203
+ offsetY = e.clientY - s.getBoundingClientRect().top;
204
+ document.body.style.cursor = 'move'; // カーソルを変更
205
+ };
206
+
207
+ document.onmousemove = function(e) {
208
+ if (isDragging) {
209
+ s.style.left = (e.clientX - offsetX) + 'px';
210
+ s.style.top = (e.clientY - offsetY) + 'px';
211
+ }
212
+ };
213
+
214
+ document.onmouseup = function() {
215
+ isDragging = false;
216
+ document.body.style.cursor = ''; // カーソルを元に戻す
217
+ };
218
+
219
+ function merp(u,t) {
220
+ switch (typeof u) {
221
+ case 'object':
222
+ u=JSON.stringify(u);
223
+ t.classList.add('EVALFUNCTION');
224
+ break;
225
+ case 'string':
226
+ u=`"${u}"`;
227
+ t.classList.add('EVALSTRING');
228
+ break;
229
+ case 'number':
230
+ case 'boolean':
231
+ t.classList.add('EVALNUMBER');
232
+ break;
233
+ case 'function':
234
+ u=u.toString();
235
+ t.classList.add('EVALFUNCTION');
236
+ break;
237
+ case 'undefined':
238
+ t.classList.add('EVALUNDEFINED');
239
+ break;
240
+ case 'symbol':
241
+ u=u.toString();
242
+ t.classList.add('EVALSTRING');
243
+ break;
244
+ }
245
+ return u;
246
+ }
247
+ console.log=function(){
248
+ for (var i=0;i<arguments.length;i++) {
249
+ var t=document.createElement("evaloutputentry"),u=arguments[i];
250
+ t.classList.add('EVALLOG');
251
+ u=merp(u,t);
252
+ t.textContent=(u+'').replace(/\s/g,'\\u00a0');
253
+ output.appendChild(t);
254
+ }
255
+ };
256
+ console.warn=function(){
257
+ for (var i=0;i<arguments.length;i++) {
258
+ var t=document.createElement("evaloutputentry"),u=arguments[i];
259
+ t.classList.add('EVALLOG');
260
+ t.classList.add('EVALWARN');
261
+ u=merp(u,t);
262
+ t.textContent=(u+'').replace(/\s/g,'\\u00a0');
263
+ output.appendChild(t);
264
+ }
265
+ };
266
+ console.error=function(){
267
+ for (var i=0;i<arguments.length;i++) {
268
+ var t=document.createElement("evaloutputentry"),u=arguments[i];
269
+ t.classList.add('EVALLOG');
270
+ t.classList.add('EVALERROR');
271
+ u=merp(u,t);
272
+ t.textContent=(u+'').replace(/\s/g,'\\u00a0');
273
+ output.appendChild(t);
274
+ }
275
+ };
276
+ }
277
+ }());