forked from js13kGames/entry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanuallinter.html
110 lines (89 loc) · 4.26 KB
/
manuallinter.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
ManualLinter - Tom Hermans<br>
Manual Linter brings all your assets (html, css, and js) into one html file, and throws a few optimizations in the mix as well. Enjoy your smaller file size!
<br>
<div>
HTML<br>
<textarea id="html" rows="20" cols="200" placeholder="Paste HTML here"></textarea>
</div>
<br>
<div>
CSS (remove most spaces, newlines, and comments). Will replace any stylesheet links with embedded css in style tags<br>
<textarea id="css_name" rows="1" cols="200" placeholder="Filename of core CSS file here"></textarea><br>
<textarea id="css" rows="20" cols="200" placeholder="Paste CSS here"></textarea>
</div>
<br>
<div>
Javascript (only up to three files at the moment, sorry! The minifier is also pretty strict at the moment, turn it off if you're having issues with it.)<br>
<textarea id="js_name_1" rows="1" cols="200" placeholder="Filename of core JS file here"></textarea><br>
<textarea id="js_1" rows="20" cols="200" placeholder="Paste JS here"></textarea>
</div>
<div>
<textarea id="js_name_2" rows="1" cols="200" placeholder="Filename of another JS file here"></textarea> <br>
<textarea id="js_2" rows="20" cols="200" placeholder="Paste JS here"></textarea>
</div>
<div>
<textarea id="js_name_3" rows="1" cols="200" placeholder="Filename of yet another JS file here"></textarea> <br>
<textarea id="js_3" rows="20" cols="200" placeholder="Paste JS here"></textarea>
</div>
<button onclick="lint()" type="button"><b>Minify & lint all</b></button><br> <br>
Output <div id="stats"></div><br>
<textarea id="output" rows="20" cols="200" placeholder="All your code inside one HTML file"></textarea>
<script>
inited = false;
document.addEventListener("DOMContentLoaded", HtmlLoaded);
function HtmlLoaded() {
html = document.getElementById("html");
css_name = document.getElementById("css_name");
css = document.getElementById("css");
js_name_1 = document.getElementById("js_name_1");
js_1 = document.getElementById("js_1");
js_name_2 = document.getElementById("js_name_2");
js_2 = document.getElementById("js_2");
js_name_3 = document.getElementById("js_name_3");
js_3 = document.getElementById("js_3");
output = document.getElementById("output");
stats = document.getElementById("stats");
inited = true;
};
function lint() {
if (inited == false) {stats.innerHTML = "Not initialized yet, please wait a bit longer"; return;}
var htmlmin = striphtml(html.value); var chars = html.value.length + css.value.length + js_1.value.length + js_2.value.length + js_3.value.length;
htmlmin.replace(/(<!--[^]+?->|\s)+/g," ").replace(/ (?=<|$)|<\/[tl].>|<.p> *(<[p/])| ?\/?(>)/gi,"$1$2");
var cssmin = stripcss(css.value);
var js1 = stripjs(js_1.value);
var js2 = stripjs(js_2.value);
var js3 = stripjs(js_3.value);
htmlmin = htmlmin.replace('<link rel="stylesheet" href="'+css_name.value+'">',"\n<style>"+cssmin+"</style>\n");
htmlmin = htmlmin.replace('<script src="'+js_name_1.value+'"></script>',"\n<script>"+js1+"</script>\n");
htmlmin = htmlmin.replace('<script src="'+js_name_2.value+'"></script>',"\n<script>"+js2+"</script>\n");
htmlmin = htmlmin.replace('<script src="'+js_name_3.value+'"></script>',"\n<script>"+js3+"</script>\n");
output.value = htmlmin
percent = (((chars - htmlmin.length) / chars) * 100).toFixed(2);
stats.innerHTML = "Went from "+chars.toString()+" characters down to "+htmlmin.length.toString()+", a save of "+percent.toString()+"%";
}
function striphtml(string) {
var temp = string;
temp = temp.replace(/(\r\n|\n|\r)/gm, ""); //Remove newlines
temp = temp.replace(/ /g,"") //Remove spaces
return(temp)
}
function stripcss(string) {
var temp = string;
temp = temp.replace(/(\r\n|\n|\r)/gm, ""); //Remove newlines
temp = temp.replace(/ /g,"") //Remove spaces
temp = temp.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1'); //Remove comments
return(temp);
}
function stripjs(string) {
var temp = string;
temp = temp.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm, '$1'); //Remove comments
temp = temp.replace(/(\r\n|\n|\r)/gm, " "); //Remove newlines
temp = temp.replace(/ /g, '');
return(temp);
}
</script>