Skip to content

Commit 59cdb7d

Browse files
authored
1.3
Clean javascript
1 parent 9e8b377 commit 59cdb7d

File tree

3 files changed

+218
-0
lines changed

3 files changed

+218
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 zvezdochiot
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.3

clean-html-js.sh

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/bin/bash
2+
# clean-html-js.sh
3+
4+
VER="1.3"
5+
GREEN="\033[1;32m"
6+
RED="\033[0;31m"
7+
YELLOW="\033[1;33m"
8+
ENDCOLOR="\033[0m"
9+
10+
tproc=`basename $0`
11+
echo -e $GREEN"$tproc version $VER"$ENDCOLOR
12+
echo ""
13+
14+
usage()
15+
{
16+
tproc=`basename $0`
17+
echo -e $YELLOW"usage:"$ENDCOLOR
18+
echo -e $GREEN" bash $tproc input.html"$ENDCOLOR
19+
echo "options:"
20+
echo " -c not clean comment (default = false);"
21+
echo " -n not verify type file (default = false);"
22+
echo " -o str output path (default = input.utf8.html);"
23+
echo " -r rewrite file (default = false);"
24+
echo " -h help."
25+
echo
26+
exit 1
27+
}
28+
29+
testcomponent()
30+
{
31+
tnocomp=""
32+
tcomp="/usr/bin/iconv"
33+
tdeb="libc-bin_*.deb"
34+
if [ ! -f "$tcomp" ]
35+
then
36+
tnocomp="$tnocomp $tcomp($tdeb)"
37+
fi
38+
tcomp="/usr/bin/enca"
39+
tdeb="enca_*.deb"
40+
if [ ! -f "$tcomp" ]
41+
then
42+
tnocomp="$tnocomp $tcomp($tdeb)"
43+
fi
44+
tcomp="/bin/sed"
45+
tdeb="sed_*.deb"
46+
if [ ! -f "$tcomp" ]
47+
then
48+
tnocomp="$tnocomp $tcomp($tdeb)"
49+
fi
50+
tcomp="/bin/grep"
51+
tdeb="grep_*.deb"
52+
if [ ! -f "$tcomp" ]
53+
then
54+
tnocomp="$tnocomp $tcomp($tdeb)"
55+
fi
56+
if [ "+$tnocomp" != "+" ]
57+
then
58+
echo -e $RED"Not found $tnocomp !"$ENDCOLOR
59+
echo ""
60+
exit 0
61+
fi
62+
}
63+
64+
main()
65+
{
66+
while getopts ":cno:rh" opt
67+
do
68+
case $opt in
69+
c) tcomment="1"
70+
;;
71+
n) tnoverify="1"
72+
;;
73+
o) tdest="$OPTARG"
74+
;;
75+
r) trewrite="1"
76+
;;
77+
h) usage
78+
;;
79+
*) echo "Unknown option -$OPTARG"
80+
exit 1
81+
;;
82+
esac
83+
done
84+
shift "$(($OPTIND - 1))"
85+
SRCNAME="$1"
86+
if [ -z "$SRCNAME" ]
87+
then
88+
usage
89+
fi
90+
echo "$src"
91+
echo ""
92+
if [ -z "$tnoverify" ]
93+
then
94+
thtml=`file "$SRCNAME" | grep "HTML document"`
95+
else
96+
thtml="HTML document"
97+
fi
98+
if [ "+$thtml" != "+" ]
99+
then
100+
NEWNAME="${SRCNAME%.htm*}"
101+
NEWNAME="$NEWNAME.utf8.html"
102+
echo " $SRCNAME -> $NEWNAME"
103+
104+
CODENAME=$(/usr/bin/enca -i "$SRCNAME")
105+
if [ "+$CODENAME" = "+" -o "+$CODENAME" = "+???" ]
106+
then
107+
CODENAME="UTF-8"
108+
elif [ "+$CODENAME" != "+UTF-8" ]
109+
then
110+
echo " Convert: $CODENAME -> UTF8"
111+
fi
112+
cat "$SRCNAME" | iconv -c -f ${CODENAME} -t UTF8 > "$NEWNAME"
113+
114+
echo -e -n "[4]: 0.."
115+
116+
echo -e -n "1.."
117+
118+
sed -i -e '
119+
s/\x0D$//
120+
s/<body/\n\L&/ig
121+
s/<iframe/\n\L&/ig
122+
s/<object/\n\L&/ig
123+
s/<d/\n\L&/ig
124+
s/<h/\n\L&/ig
125+
s/<l/\n\L&/ig
126+
s/<m/\n\L&/ig
127+
s/<p/\n\L&/ig
128+
s/<t/\n\L&/ig
129+
s/<\/body/\n\L&/ig
130+
s/<\/h/\n\L&/ig
131+
s/<script/\n\L&/ig
132+
s/<\/script>/\n\L&\n/ig
133+
s/<noscript/\n\L&/ig
134+
s/<\/noscript>/\n\L&\n/ig
135+
s/<iframe/\n\L&/ig
136+
s/<\/iframe>/\n\L&\n/ig
137+
s/<object/\n\L&/ig
138+
s/<\/object>/\n\L&\n/ig
139+
s/<ins/\n\L&/ig
140+
s/<\/ins>/\n\L&\n/ig
141+
s/<\!--/\n\L&/ig
142+
s/-->/\n\L&\n/ig
143+
' "$NEWNAME"
144+
145+
echo -e -n "2.."
146+
147+
sed -i -e '
148+
/^<script/,/^<\/script>/d
149+
/^<noscript/,/^<\/noscript>/d
150+
/^<iframe/,/^<\/iframe>/d
151+
/^<object/,/^<\/object>/d
152+
/^<ins/,/^<\/ins>/d
153+
' "$NEWNAME"
154+
155+
echo -e -n "3.."
156+
157+
if [ -z "$tcomment" ]
158+
then
159+
sed -i -e '
160+
/^<\!--/,/^-->/d
161+
' "$NEWNAME"
162+
fi
163+
164+
echo -e -n "4.."
165+
166+
sed -i -e '
167+
s/content="text\/html; charset=.*">/content="text\/html; charset=utf-8">/ig
168+
s/[ \t]*$//
169+
/^$/d
170+
' "$NEWNAME"
171+
172+
flgpre=`grep -i "<pre" "$NEWNAME"`
173+
if [ "+$flgpre" = "+" ]
174+
then
175+
echo -e -n "(5).."
176+
177+
sed -i -e '
178+
s/^[ \t]*//
179+
/^$/d
180+
' "$NEWNAME"
181+
fi
182+
183+
echo -e "END"
184+
if [ ! -z "$trewrite" ]
185+
then
186+
mv -fv "$NEWNAME" "$SRCNAME"
187+
fi
188+
exit 0
189+
else
190+
file "$1"
191+
exit 1
192+
fi
193+
}
194+
195+
testcomponent
196+
main "$@"

0 commit comments

Comments
 (0)