soiz commited on
Commit
bb2712d
·
verified ·
1 Parent(s): 7ef74a1

Update cl.js

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