Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e4b8363

Browse files
JavaScript Debugger移転。
1 parent 357b256 commit e4b8363

File tree

3 files changed

+1741
-0
lines changed

3 files changed

+1741
-0
lines changed

‎Script/JsColorizer.js‎

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
/*
2+
* DO NOT REMOVE THIS NOTICE
3+
*
4+
* PROJECT: JsDecoder
5+
* VERSION: 1.1.0
6+
* COPYRIGHT: (c) 2004-2008 Cezary Tomczak
7+
* LINK: http://code.gosu.pl
8+
* LICENSE: GPL
9+
*/
10+
11+
function JsColorizer() {
12+
this.color = {
13+
"keyword": "#0000FF",
14+
"object": "#FF0000",
15+
"quotation": "#FF00FF",
16+
"comment": "#008000"
17+
};
18+
19+
this.s = ""; // code to colorize
20+
this.i = 0;
21+
this.len = 0;
22+
23+
this.ret = ""; // colorized code
24+
this.lastWord = ""; // last alphanumeric word
25+
this.nextChar = "";
26+
this.prevChar = "";
27+
28+
this.code = [""];
29+
this.row = 0;
30+
31+
this.times = {
32+
quotation: 0, quotation_calls: 0,
33+
lineComment: 0, lineComment_calls: 0,
34+
comment: 0, comment_calls: 0,
35+
slash: 0, slash_calls: 0,
36+
word: 0, word_calls: 0
37+
};
38+
39+
this.write = function (s)
40+
{
41+
this.code[this.row] += s;
42+
if (s.length == 1) {
43+
this.prevChar = s;
44+
} else {
45+
this.prevCharInit();
46+
}
47+
};
48+
this.writeLine = function ()
49+
{
50+
this.code.push("");
51+
this.row++;
52+
this.prevChar = "\n";
53+
};
54+
this.prevCharInit = function ()
55+
{
56+
this.prevChar = this.code[this.row].charAt(this.code[this.row].length - 1);
57+
};
58+
59+
this.showTimes = function ()
60+
{
61+
var ret = '';
62+
for (var f in this.times) {
63+
var t = this.times[f];
64+
if (/_calls/.test(f)) {
65+
ret += f+': '+t+"\n";
66+
} else {
67+
ret += f+': '+time_round(t)+" sec\n";
68+
}
69+
}
70+
return ret;
71+
};
72+
73+
this.colorize = function()
74+
{
75+
this.len = this.s.length;
76+
while (this.i < this.len)
77+
{
78+
var c = this.s.charAt(this.i);
79+
if (this.len - 1 == this.i) {
80+
this.nextChar = "";
81+
} else {
82+
this.nextChar = this.s.charAt(this.i + 1);
83+
}
84+
switch (c) {
85+
case "\n":
86+
if (this.lastWord.length) { this.word(); }
87+
this.lastWord = '';
88+
this.writeLine();
89+
break;
90+
case "'":
91+
case '"':
92+
case "`":
93+
if (this.lastWord.length) { this.word(); }
94+
this.lastWord = '';
95+
this.quotation(c);
96+
break;
97+
case "/":
98+
if (this.lastWord.length) { this.word(); }
99+
this.lastWord = '';
100+
if ("/" == this.nextChar) {
101+
this.lineComment();
102+
} else if ("*" == this.nextChar) {
103+
this.comment();
104+
} else {
105+
this.slash();
106+
}
107+
break;
108+
default:
109+
if (/^\w$/.test(c)) {
110+
this.lastWord += c;
111+
} else {
112+
if (this.lastWord.length) { this.word(); }
113+
this.lastWord = '';
114+
this.write(c);
115+
}
116+
break;
117+
}
118+
this.i++;
119+
}
120+
this.write(this.lastWord);
121+
return this.code.join("\n");
122+
};
123+
124+
this.quotation = function(quotation)
125+
{
126+
//var time = time_start();
127+
var s = quotation;
128+
var escaped = false;
129+
while (this.i < this.len - 1) {
130+
this.i++;
131+
var c = this.s.charAt(this.i);
132+
if ("\\" == c) {
133+
escaped = (escaped ? false : true);
134+
}
135+
s += c;
136+
if (c == quotation) {
137+
if (!escaped) {
138+
break;
139+
}
140+
}
141+
if ("\\" != c) {
142+
escaped = false;
143+
}
144+
}
145+
this.write('<font color="'+this.color.quotation+'">' + s + '</font>');
146+
//this.times.quotation += time_get(time);
147+
//this.times.quotation_calls++;
148+
};
149+
150+
this.lineComment = function()
151+
{
152+
//var time = time_start();
153+
var s = "//";
154+
this.i++;
155+
while (this.i < this.len - 1) {
156+
this.i++;
157+
var c = this.s.charAt(this.i);
158+
s += c;
159+
if ("\n" == c) {
160+
break;
161+
}
162+
}
163+
this.write('<font color="'+this.color.comment+'">' + s + '</font>');
164+
//this.times.lineComment += time_get(time);
165+
//this.times.lineComment_calls++;
166+
};
167+
168+
this.comment = function()
169+
{
170+
//var time = time_start();
171+
var s = "/*";
172+
this.i++;
173+
var c = "";
174+
var prevC = "";
175+
while (this.i < this.len - 1) {
176+
this.i++;
177+
prevC = c;
178+
c = this.s.charAt(this.i);
179+
s += c;
180+
if ("/" == c && "*" == prevC) {
181+
break;
182+
}
183+
}
184+
this.write('<font color="'+this.color.comment+'">' + s + '</font>');
185+
//this.times.comment += time_get(time);
186+
//this.times.comment_calls++;
187+
};
188+
189+
/* SLASH
190+
* divisor /= or *\/ (4/5 , a/5)
191+
* regexp /\w/ (//.test() , var asd = /some/;) */
192+
this.slash = function()
193+
{
194+
//var time = time_start();
195+
var a_i = this.i - 1;
196+
var a_c = this.s.charAt(a_i);
197+
for (a_i = this.i - 1; a_i >= 0; a_i--) {
198+
var c2 = this.s.charAt(a_i);
199+
if (" " == c2 || "\t" == c2) {
200+
continue;
201+
}
202+
a_c = this.s.charAt(a_i);
203+
break;
204+
}
205+
var a = /^\w+$/.test(a_c) || ']' == a_c || ')' == a_c;
206+
var b = ("*" == this.prevChar);
207+
if (a || b) {
208+
if (a) {
209+
if ("=" == this.nextChar) {
210+
this.write("/");
211+
} else {
212+
this.write("/");
213+
}
214+
} else if (b) {
215+
this.write("/");
216+
}
217+
} else if (')' == this.prevChar) {
218+
this.write('/');
219+
} else {
220+
var ret = '';
221+
if ("=" == this.prevChar) {
222+
ret += "/";
223+
} else {
224+
ret += "/";
225+
}
226+
var escaped = false;
227+
while (this.i < this.len - 1) {
228+
this.i++;
229+
var c = this.s.charAt(this.i);
230+
if ("\\" == c) {
231+
escaped = (escaped ? false : true);
232+
}
233+
ret += c;
234+
if ("/" == c) {
235+
if (!escaped) {
236+
break;
237+
}
238+
}
239+
if ("\\" != c) {
240+
escaped = false;
241+
}
242+
}
243+
this.write('<font color="'+this.color.quotation+'">' + ret + '</font>');
244+
}
245+
//this.times.slash += time_get(time);
246+
//this.times.slash_calls++;
247+
};
248+
249+
this.word = function()
250+
{
251+
//var time = time_start();
252+
if (this.keywords.indexOf(this.lastWord) != -1) {
253+
this.write('<font color="'+this.color.keyword+'">' + this.lastWord + '</font>');
254+
} else if (this.objects.indexOf(this.lastWord) != -1) {
255+
this.write('<font color="'+this.color.object+'">' + this.lastWord + '</font>');
256+
} else {
257+
this.write(this.lastWord);
258+
}
259+
//this.times.word += time_get(time);
260+
//this.times.word_calls++;
261+
};
262+
263+
this.keywords = [
264+
"abstract", "boolean", "break", "byte",
265+
"case", "catch", "char", "class", "const", "constructor", "continue",
266+
"default", "delete", "do", "double",
267+
"else", "extends",
268+
"false", "final", "finally", "float", "for", "function",
269+
"goto",
270+
"if", "implements", "import", "in", "instanceof", "int", "interface",
271+
"let", "long",
272+
"native", "new", "null",
273+
"package", "private", "protected", "public",
274+
"return",
275+
"short", "static", "super", "switch", "synchronized",
276+
"this", "throw", "throws", "transient", "true", "try", "typeof",
277+
"var", "void",
278+
"while", "with"
279+
];
280+
281+
this.objects = [
282+
"Anchor", "anchors", "Applet", "applets", "Area", "Array", "Button", "Checkbox",
283+
"Date", "document", "FileUpload", "Form", "forms", "Frame", "frames", "Hidden", "history",
284+
"Image", "images", "Link", "links", "Area", "location", "Math", "MimeType", "mimeTypes",
285+
"navigator", "options", "Password", "Plugin", "plugins", "Radio", "Reset", "Select",
286+
"String", "Submit", "Text", "Textarea", "window"
287+
];
288+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /