Вставьте ваш css код в поле:<br><textarea cols="100" rows="12" wrap="virtual" id="code"></textarea><br><input type="button" value="Сжать css" onclick="compress(1)"/><input type="button" value="Восстановить css" onclick="restore()"/><br><table width="63%" border="0" cellspacing="3" cellpadding="0"><tr><td width="100">До сжатия:</td><td align="left" valign="middle" style="background:#dddddd;"><div id="before" style="width:1px;"></div></td></tr><tr><td>После сжатия:</td><td align="left" valign="middle" style="background:#dddddd;"><div id="after" style="width:1px;"></div></td></tr></table><textarea cols="100" rows="12" wrap="off" id="result" onclick="this.select()"></textarea>
<script>
// Создано Aleko
code = document.getElementById('code');
before = document.getElementById('before');
after = document.getElementById('after');
result = document.getElementById('result');
function compress(par){
proc = code.value
.replace(/(
092;n|
092;r|
092;t|
092;v)/g,'') // переносы строк, табы
.replace(/
092;/
092;*(.*?)
092;*
092;//g,'') // комментарии
.replace(/
092;s*(em|ex|px|pt|pc|in|mm|cm|%)([^
092;w])/ig,'$1$2') // пробелы перед величинами
.replace(/([^
092;d]0)(em|ex|px|pt|pc|in|mm|cm|%)/ig,'$1') // замена нулевых значений
.replace(/
092;s*(
092;{|
092;}|
092;;|
092;:|
092;,|
092;])
092;s*/g,'$1') // лишние пробелы в значениях
.replace(/^
092;s*/g,'') // лишние пробелы в начале
.replace(/
092;s*
092;!important/g,'!important') // лишние пробелы
.replace(/
092;[
092;s*/g,'[') // лишние пробелы в css3
.replace(/([
092;#
092;.
092;@
092;[
092;]]*
092;w*)
092;s+([
092;#
092;.
092;@
092;[
092;]]*
092;w*)/g,'$1 $2') // лишние пробелы между селекторами
.replace(/
092;#([0-9a-f]{1})
092;1([0-9a-f]{1})
092;2([0-9a-f]{1})
092;3/ig,'#$1$2$3') // краткие цвета
.replace(/([^
092;w])bold([^
092;w])/g,'$1700$2') // bold
.replace(/(^|
092;})[^
092;{
092;}]+?(
092;{
092;s*
092;})/g,'$1')
.replace(/{([^
092;}
092;{]*)}/g,function(m){ // margin-top:0;margin-right:0;
var pt,pr,pb,pl;
if(m.match(/padding-top
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){pt=m.replace(/.*padding-top
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/padding-right
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){pr=m.replace(/.*padding-right
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/padding-bottom
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){pb=m.replace(/.*padding-bottom
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/padding-left
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){pl=m.replace(/.*padding-left
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
var mt,mr,mb,ml;
if(m.match(/margin-top
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){mt=m.replace(/.*margin-top
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/margin-right
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){mr=m.replace(/.*margin-right
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/margin-bottom
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){mb=m.replace(/.*margin-bottom
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(m.match(/margin-left
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)/ig)){ml=m.replace(/.*margin-left
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0).*/ig,'$1');}
if(pt&&pl&&pr&&pb){
var outp = m.replace(/padding-(top|right|bottom|left)
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)(;?)/ig,'');
outp = outp.replace(/
092;{|
092;}/g,'');
return "{padding:"+pt+" "+pr+" "+pb+" "+pl+";"+outp+"}";
}
if(mt&&ml&&mr&&mb){
var outm = m.replace(/margin-(top|right|bottom|left)
092;:(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)(;?)/ig,'');
outm = outm.replace(/
092;{|
092;}/g,'');
return "{margin:"+mt+" "+mr+" "+mb+" "+ml+";"+outm+"}";
}
if(!outm&&!outp){return m;}
})
.replace(/(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s
092;1
092;s
092;1
092;s
092;1/ig,'$1') // margin:0 0 0 0;
.replace(/(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s
092;1
092;s
092;3/ig,'$1 $3') //margin:0 1 0 1;
.replace(/(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s(
092;d+(em|ex|px|pt|pc|in|mm|cm|%)|0)
092;s
092;3/ig,'$1 $3 $5') //margin:0 1 2 1;
.replace(/
092;;
092;}/g,'}') // точка с запятой в конце условия
.replace(/
092;;{2,}/g,';') // лишние точки с запятой
.replace(/
092;s{2,}/g,' '); // больше одного пробела подряд
if(par==1){result.value = proc;}
data(par);
};
function data(par){
if(par==1){
before.style.width = "100%";
before.innerHTML = " "+parseInt(code.value.length)+" байт";
after.style.width = parseInt(result.value.length/(code.value.length/100))+"%";
after.innerHTML = " "+parseInt(result.value.length)+" байт";
}else{
before.style.width = "1px";
before.innerHTML = "";
after.style.width = "1px";
after.innerHTML = "";
}
};
function restore(){
compress(0);
result.value = proc
.replace(/,/g,', ')
.replace(/([^{])}/g,'$1;}
092;n')
.replace(/
092;#([0-9a-f])([0-9a-f])([0-9a-f])(?!
092;w)/ig,'#$1$1$2$2$3$3')
.replace(/
092;#([a-f0-9]{6})(?!
092;w)/ig,function(m){return m.toUpperCase()})
//.replace(/([^)]){([^}])/g,'$1 {
092;n
092;t$2')
//.replace(/{}/g,'{}
092;n
092;n')
//.replace(/;(?=
092;w|})/g,';
092;n
092;t')
.replace(/;([
092;#
092;.
092;@
092;[])/g,';
092;n
092;n$1')
.replace(/
092;!important/g,' !important')
.replace(/
092;s*$/g,'');
};
</script>
К примеру этот скрипт после вставки его в редактор в панели половина кода пропадает и в итоге скрипт не работает...