18910140161

实现CSS在线美化(格式化)、压缩、加密、解密、混淆工具-toolfk程序员工具网

顺晟科技

2022-09-14 10:45:51

105

    本文要推荐的[ToolFk]是一款程序员经常使用的线上免费测试工具箱,ToolFk 特色是专注于程序员日常的开发工具,不用安装任何软件,只要把内容贴上按一个执行按钮,就能获取到想要的内容结果。ToolFk还支持  BarCode条形码在线生成、 QueryList采集器、 PHP代码在线运行、 PHP混淆、加密、解密、 Python代码在线运行、JavaScript在线运行、YAML格式化工具、HTTP模拟查询工具、HTML在线工具箱、JavaScript在线工具箱、CSS在线工具箱、JSON在线工具箱、Unixtime时间戳转换、Base64/URL/Native2Ascii转换、CSV转换工具箱、XML在线工具箱、WebSocket在线工具、Markdown 在线工具箱、Htaccess2nginx 转换、进制在线转换、在线加密工具箱、在线伪原创工具、在线APK反编译、在线网页截图工具、在线随机密码生成、在线生成二维码Qrcode、在线Crontab表达式生成、在线短网址生成、在线计算器工具。等20多个日常程序员开发工具,算是一个非常全面的程序员工具箱网站。

 

網站名稱:ToolFk
網站鏈結:https://www.toolfk.com/
工具链接:https://www.toolfk.com/tool-format-css

代码教學

本工具[在线CSS美化(格式化)/加密/解密/混淆]依赖于Codemirror,它的Github地址为:https://github.com/codemirror/CodeMirror, 加密、解密使用到http://dean.edwards.name/packer/ 库,美化使用到csso-browser库,https://github.com/css/csso   。使用代码如下

STEP 1

STEP 2

核心代码如下

beautify_start:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }

    toolfk.beautify_default.beautify_in_progress = true;
    if (opts.language === \'html\') {
        output = beautifier.html(source, opts);
    } else if (opts.language === \'css\') {
        output = beautifier.css(source, opts);
    } else {
        if (opts.detect_packers) {
            source = toolfk.beautify_unpacker_filter(source);
        }
        output = beautifier.js(source, opts);
    }

    opts.target.setValue(output);
    toolfk.report(\'beautify\',output);
    toolfk.beautify_default.beautify_in_progress = false;
},

pack_js:function(options) {
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;

    var packer = new Packer;
    if (opts.is_base64) {
        var output = packer.pack(source, 1, opts.is_shrink);
    } else {
        var output = packer.pack(source, 0, opts.is_shrink);
    }
    opts.target.setValue(output);
    toolfk.report(\'compress\',output);
    toolfk.beautify_default.beautify_in_progress = false;
},

dec_pack:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;
    try {
        eval(\'var value=String\' + source.slice(4));
        opts.target.setValue(value);
        toolfk.report(\'deciphering-compress\',value);
    } catch (e) {
        layer.msg(TEXT_ERROR);
    }
    toolfk.beautify_default.beautify_in_progress = false;
},

dec_pack_shrink:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;
    try {
        eval(\'var value=String\' + source.slice(4));
        var source = toolfk.beautify_unpacker_filter(value);
        output = beautifier.js(source, opts);
        opts.target.setValue(output);
        toolfk.report(\'decode-code\',output);
    } catch (e) {
        layer.msg(TEXT_ERROR);
    }
    toolfk.beautify_default.beautify_in_progress = false;
},

code_code:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var target = opts.target.getValue();
    if(target==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;
    new ClipboardJS(\'.copy-code\', {
        text: function(trigger) {
            layer.msg(COPY_SUCC);
            return target;
        }
    });
    toolfk.beautify_default.beautify_in_progress = false;
},

/* css */
purify_css:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;

    var value   =   toolfk.purify_encode(source).replace(/\}/g,\'}\n\');
    opts.target.setValue(value);
    toolfk.report(\'purify_css\',value);
    toolfk.beautify_default.beautify_in_progress = false;
},

purify_encode:function(text){
    var val = text;
    val = val.replace(/\/\*(.|\n)*?\*\//g,\'\');          //去除注释
    val = val.replace(/^\s+|\s+$/g,\'\');                   //清除首尾空格
    val = val.replace(/(:)\s+/g,\'$1\');                     //去除 冒号后多个空格              如 width:  100px  => width:100px
    val = val.replace(/\s{2,}/g,\' \');                      //去除 多余空格2个以上             如 margin: 10px   20px  30px  => margin:10px 20px 30px
    val = val.replace(/,\s+|\s+,/g,\',\');                //去除 多个样式共享时的多余空格    如 h1,  h2  , h3  =>h1,h2,h3
    val = val.replace(/;{2,}|;\s+/g,\';\');               //去除 多个分号或分号后面多余空格  如 width:200px;;  height:100px  => width:200px;height:100px
    val = val.replace(/\s*\{\s*/g,\'{\');                   //去除 选择符后面多余空格          如 div { height:100px}   => div{height:100px}
    val = val.replace(/\s*}\s*/g,\'}\');                //去除 选择器前面多余空格          如 div{height:100px}  a{}   => div{height:100px}a{}
    val = val.replace(/[\n\t\f\r]/g,\'\');               //去除换行,制表符,分页符,回车
    val = val.replace(/;}/g,\'}\');
    return val;
},

optimize_css:function(options){
    if (toolfk.beautify_default.beautify_in_progress) {
        return;
    }
    var opts = $.extend({},toolfk.beautify_default, options);

    var source = opts.source.getValue();
    if(source==\'\'){
        return layer.msg(NOT_EMPTY);
    }
    toolfk.beautify_default.beautify_in_progress = true;

    var lastResult = csso.minify(source, {
        restructure: true
    });

    var value   =   lastResult.css;
    opts.target.setValue(value);
    toolfk.report(\'optimize_css\',value);
    toolfk.beautify_default.beautify_in_progress = false;
},

 

 

值得一試的三個理由:

  1. 整合各種程序员开发中经常使用的开发测试工具。

  2. 简洁美观大气的网站页面

  3. 支持 在线格式化执行代码、APK在线反编译、在线高强度密码生成、在线网页截图 等二十多種工具服务

  4. 同时还推荐一下它的姐妹网 www.videofk.com 视频下载工具箱 

 

本文链接:http://www.hihubs.com/article/367

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航