zxlie 8 ani în urmă
părinte
comite
ff1593d6cd

+ 2 - 0
v2.0/apps/background/index.js

@@ -6,6 +6,7 @@ var BgPageInstance = (function () {
 
     let MSG_TYPE = Tarp.require('../static/js/msg_type');
     let Settings = Tarp.require('../options/settings');
+
     let feHelper = {};
     let devToolsDetected = false;
 
@@ -344,6 +345,7 @@ var BgPageInstance = (function () {
      * @private
      */
     let _qrDecode = function (info, tab) {
+        let qrcode = Tarp.require('../static/vendor/zxing/zxing.min.js');
         qrcode.callback = function (text) {
             if ((text || '').indexOf('error decoding QR Code') !== -1) {
                 let image = new Image();

+ 2 - 1
v2.0/apps/manifest.json

@@ -58,7 +58,8 @@
             "js": [
                 "static/vendor/jquery/jquery-3.3.1.min.js",
                 "static/vendor/require/require.js",
-                "json-format/automatic.js"
+                "json-format/automatic.js",
+                "qr-code/decode.js"
             ],
             "run_at": "document_end",
             "all_frames": false

+ 60 - 0
v2.0/apps/qr-code/decode.js

@@ -0,0 +1,60 @@
+/**
+ * FeHelper QR码解码
+ */
+let qrDecode = (function () {
+
+    "use strict";
+
+    let _show = function(text){
+        let el = $('#__fehelper_qr_decode__');
+        if(!el[0]){
+            el = $('<div id="__fehelper_qr_decode__" style="z-index:999999;position: fixed;left:0;top:0;right: 0;bottom: 0;display: none;">' +
+                '<div style="position: fixed;left:0;top:0;right: 0;bottom: 0;background: #000;opacity: 0.5;"></div>' +
+                '<div style="position: relative;top: 100px;left: ' + ($('body').width() / 2 - 200) + 'px;border:1px solid #000;background:#fff;width:420px;padding:15px;border-radius:5px 5px;box-shadow:2px 2px 5px #000;">' +
+                '<div style="margin: 0 0 10px 0;font-size: 14px;font-weight: bold;">二维码解码结果:</div>' +
+                '<textarea style="display:block;border-radius:5px 5px;width:398px;border:1px solid #aaa;min-height:80px;resize:none;box-shadow:2px 2px 5px #aaa;padding:10px;font-size:14px;color:#888;"></textarea>' +
+                '<div style="margin-top:10px;">' +
+                '<span id="__fehelper_qr_msg_" style="float: right;color:#f00;display:none;">复制成功!</span>' +
+                '<a id="__fehelper_qr_copy_" style="margin-right:20px;color: #00f;text-decoration: underline" href="#">复制</a>' +
+                '<a id="__fehelper_qr_close_" style="margin-top:10px;color: #00f;text-decoration: underline" href="#">关闭</a>' +
+                '</div></div>' +
+                '</div>').appendTo('body');
+
+            el.find('a#__fehelper_qr_copy_').click(function(e){
+                e.preventDefault();
+
+                el.find('textarea').select();
+                document.execCommand('Copy');
+
+                el.find('#__fehelper_qr_msg_').show().delay(2000).hide('slow');
+            });
+            el.find('a#__fehelper_qr_close_').click(function(e){
+                e.preventDefault();
+                el.hide('slow');
+            });
+        }
+
+        if(text === 'error decoding QR Code') {
+            text = '抱歉,二维码识别失败!';
+        }
+
+        el.show('slow').find('textarea').val(text);
+    };
+
+    let _init = function () {
+        // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
+        chrome.runtime.onMessage.addListener(function (request, sender, callback) {
+            let MSG_TYPE = Tarp.require('../static/js/msg_type');
+            if (request.type === MSG_TYPE.QR_DECODE) {
+                _show(request.result);
+            }
+        });
+
+    };
+
+    return {
+        init: _init
+    };
+})();
+
+qrDecode.init();

+ 115 - 0
v2.0/apps/regexp/index.css

@@ -0,0 +1,115 @@
+@import url("../static/css/bootstrap.min.css");
+
+html {
+    font-size:14px
+}
+body {
+    background-color: #eee;
+    font-family:Arial, "simsun";
+    color:#666
+}
+.pannel-select{
+    position: absolute;
+    right: 0;
+    top: 0;
+    width: 255px;
+    height: 30px;
+}
+.reglist_select{
+    padding: 0 0;
+    height: 24px;
+}
+.reg_link{
+    display: inline-block;
+    float: right;
+    text-align: right;
+    font-size: 12px;
+    margin-top: 4px;
+}
+.reg_pre{
+    border: none;
+    background: transparent;
+}
+.reg_reg_input{
+    resize:none;
+}
+.reg_textarea{
+    padding: 0;
+    width: 954px;
+    resize: none;
+    font: 100%"courier new", monospace;
+}
+#srcWrapper{
+    padding: 12px;
+}
+.wrapper #srcBackground{
+    padding: 0;
+}
+.mod-regexp {
+    width: 980px;
+    margin: 0 auto;
+    padding: 0;
+    background: #FFF;
+}
+#srcWrapper {
+    background:#fff;
+    border:1px solid #ccc;
+    min-height:50px;
+    position:relative;
+    border-radius: 4px;
+    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
+    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
+    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
+    -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
+    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
+}
+
+#srcBackground {
+    padding:4px;
+    margin:0;
+    position:absolute;
+    z-index:1;
+    width:954px;
+    word-break: break-all;
+    line-height:14px;
+}
+#srcBackground i, #srcBackground b {
+    font: 100% "courier new",monospace;
+    font-style:normal;
+    font-weight:normal;
+    font-size:14px;
+    margin:0;
+    padding:0;
+    background:#fff;
+    color:#fff
+}
+#srcBackground b {
+    background:#dd0;
+    color:#dd0
+}
+#srcCode {
+    background:transparent;
+    margin:0;
+    border:none;
+    font-size:14px;
+    position:relative;
+    z-index:2;
+    outline:none;
+    overflow-y:hidden
+}
+
+#rstCount {
+    color:#f00
+}
+#rstCode {
+    padding:3px
+}
+#regTip {
+    font-size:12px;
+    color:#d00;
+    display:none
+}
+.x-tip {
+    font-size:12px;
+    color:#00b
+}

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
v2.0/apps/regexp/index.html


+ 222 - 0
v2.0/apps/regexp/index.js

@@ -0,0 +1,222 @@
+/**
+ * FeHelper 正则工具
+ */
+
+/**
+ * 自适应高度的jquery插件
+ */
+$.fn.extend({
+    textareaAutoHeight:function (options) {
+        this._options = {
+            minHeight:0,
+            maxHeight:100000
+        };
+
+        this.init = function () {
+            for (var p in options) {
+                this._options[p] = options[p];
+            }
+            if (this._options.minHeight === 0) {
+                this._options.minHeight = parseFloat($(this).height());
+            }
+            for (var p in this._options) {
+                if ($(this).attr(p) == null) {
+                    $(this).attr(p, this._options[p]);
+                }
+            }
+            $(this).keyup(this.resetHeight).change(this.resetHeight)
+                .focus(this.resetHeight);
+        };
+        this.resetHeight = function () {
+            var _minHeight = parseFloat($(this).attr("minHeight"));
+            var _maxHeight = parseFloat($(this).attr("maxHeight"));
+
+            $(this).height(0);
+            var h = parseFloat(this.scrollHeight);
+            h = h < _minHeight ? _minHeight :
+                h > _maxHeight ? _maxHeight : h;
+            $(this).height(h).scrollTop(h);
+            if (h >= _maxHeight) {
+                $(this).css("overflow-y", "scroll");
+            }
+            else {
+                $(this).css("overflow-y", "hidden");
+            }
+        };
+        this.init();
+    }
+});
+
+var RegExpTools = (function () {
+
+    "use strict";
+
+    var regElm, srcElm, rstElm, rstCount, srcBackgroundElm, srcWrapperElm, regListElm;
+    var ID_PREFIX = 'tmp_id_';
+    var TAG_MATCHED = 'b';
+    var TAG_NOT_MATCHED = 'i';
+    var TR_ID_PREFIX = 'tr_' + ID_PREFIX;
+
+    var _getRegExp = function (regTxt) {
+        try {
+            return new Function('return ' + regTxt)();
+        } catch (e) {
+            return null;
+        }
+    };
+
+    var _buildTable = function (rstArray) {
+        var tbl = ["<table class='table table-bordered table-striped table-condensed table-hover'>"];
+        tbl.push('<tr class="active"><th class="num">序号</th><th>匹配结果</th><th>在原字符串中的位置</th></tr>')
+        $.each(rstArray, function (i, item) {
+            tbl.push('<tr id="' + TR_ID_PREFIX + item.index + '" data-index="' + item.index + '">');
+            tbl.push('<td class="num">' + (i + 1) + '</td>'
+                + '<td class="content">' + item.text + '</td>'
+                + '<td class="index">' + item.index + '</td>');
+            tbl.push('</tr>');
+        });
+        tbl.push('</table>');
+        return tbl.join('');
+    };
+
+    var _createTag = function (type, item) {
+        var tags = [];
+        for (var i = 0, len = item.text.length; i < len; i++) {
+            tags.push('<' + type + ' data-id="' + ID_PREFIX + item.index + '">'
+                + item.text.charAt(i) + '</' + type + '>');
+        }
+        return tags.join('');
+    };
+
+    var _blinkHighlight = function () {
+        $('tr[id^=' + TR_ID_PREFIX + ']').click(function (e) {
+            var index = $(this).attr('data-index');
+            var tags = $(TAG_MATCHED + '[data-id=' + ID_PREFIX + index + ']');
+            tags.animate({
+                opacity:0
+            }, 200).delay().animate({
+                    opacity:1
+                }, 200).delay().animate({
+                    opacity:0
+                }, 200).delay().animate({
+                    opacity:1
+                }, 200);
+        });
+    };
+
+    var _highlight = function (srcText, rstArray) {
+        if (!srcText) {
+            srcBackgroundElm.html('');
+            return;
+        }
+        var hl = [];
+        var preIndex = 0;
+        $.each(rstArray, function (i, item) {
+            if (i === 0) {
+                if (item.index === 0) {
+                    hl.push(_createTag(TAG_MATCHED, item));
+                } else {
+                    hl.push(_createTag(TAG_NOT_MATCHED, {
+                        index:0,
+                        text:srcText.substring(0, item.index)
+                    }));
+                    hl.push(_createTag(TAG_MATCHED, item));
+                }
+            } else {
+                preIndex = rstArray[i - 1].index + rstArray[i - 1].text.length;
+                hl.push(_createTag(TAG_NOT_MATCHED, {
+                    index:preIndex,
+                    text:srcText.substring(preIndex, item.index)
+                }));
+                hl.push(_createTag(TAG_MATCHED, item));
+            }
+        });
+        srcBackgroundElm.html(hl.join(''));
+        _blinkHighlight();
+    };
+
+    var _emptyTable = function (message) {
+        var tbl = ["<table class='table table-bordered table-striped table-condensed table-hover'>"];
+        tbl.push('<tr class="active"><th class="num">序号</th><th>匹配结果</th></tr>');
+        tbl.push('<tr><td colspan="2">' + message + '</td></tr>');
+        tbl.push('</table>');
+        return tbl.join('');
+    };
+
+    var _dealRegMatch = function (e) {
+        srcWrapperElm.height(srcElm.height() + 24);
+
+        var regTxt = regElm.val().trim();
+        var srcTxt = srcElm.val().trim();
+        if (!regTxt || !srcTxt) {
+            rstElm.html(_emptyTable('不能匹配'));
+            rstCount.html('0个');
+            _highlight();
+        } else {
+            var reg = _getRegExp(regTxt);
+            if (!reg || !reg instanceof RegExp) {
+                rstElm.html(_emptyTable('正则表达式错误!'));
+                rstCount.html('0个');
+                _highlight();
+                return;
+            }
+            var rst = [];
+            // 用字符串的replace方法来找到匹配目标在元字符串中的准确位置
+            srcTxt.replace(reg, function () {
+                var matchedTxt = arguments[0];
+                var txtIndex = arguments[arguments.length - 2];
+                rst.push({
+                    text:matchedTxt,
+                    index:txtIndex
+                });
+            });
+            if (!rst || !rst.length) {
+                rstElm.html(_emptyTable('不能匹配'));
+                rstCount.html('0个');
+                _highlight();
+            } else {
+                rstElm.html(_buildTable(rst));
+                rstCount.html(rst.length + '个');
+                _highlight(srcElm.val(), rst);
+            }
+        }
+    };
+
+    var _init = function () {
+        $(function () {
+            regElm = $('#regText');
+            srcElm = $('#srcCode');
+            srcBackgroundElm = $('#srcBackground');
+            srcWrapperElm = $('#srcWrapper');
+            rstElm = $('#rstCode').html(_emptyTable('暂无输入'));
+            rstCount = $('#rstCount');
+            regListElm = $('#regList');
+
+            // 输入框自适应高度
+            regElm.textareaAutoHeight({minHeight:34});
+            srcElm.textareaAutoHeight({minHeight:50});
+            srcBackgroundElm.textareaAutoHeight({minHeight:50});
+
+            // 监听两个输入框的按键、paste、change事件
+            $('#regText,#srcCode').keyup(_dealRegMatch).change(_dealRegMatch)
+                .bind('paste', _dealRegMatch);
+
+            regListElm.change(function (e) {
+                var reg = $(this).val();
+                var regTipElm = $('#regTip');
+                regElm.val(reg);
+                if (!reg) {
+                    regTipElm.hide();
+                } else {
+                    regTipElm.show();
+                }
+            });
+        });
+    };
+
+    return {
+        init:_init
+    };
+})();
+
+RegExpTools.init();

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
v2.0/apps/static/vendor/zxing/zxing.min.js


+ 26 - 0
v2.0/apps/timestamp/index.css

@@ -0,0 +1,26 @@
+@import url("../static/css/bootstrap.min.css");
+
+.mod-timestamp{
+    width:950px;
+    margin:20px auto 0;
+    padding:5px 15px;
+    background:#fff;
+    border:1px solid #bbb
+}
+.mod-timestamp .x-input div{
+    margin:5px 0
+}
+#txtNowDate,#txtNow,#txtDesStamp,#txtSrcStamp,#txtDesDate,#txtLocale{
+    width:300px;
+}
+#txtNowDate,#txtNow,#txtDesStamp,#txtDesDate{
+    color:#666;
+    font-weight:500
+}
+#txtSrcYear,#txtSrcMonth,#txtSrcDay,#txtSrcHour,#txtSrcMinute,#txtSrcSecond{
+    width:40px;
+}
+
+.mod-time-input{
+    width: 80px;
+}

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
v2.0/apps/timestamp/index.html


+ 56 - 0
v2.0/apps/timestamp/index.js

@@ -0,0 +1,56 @@
+/**
+ * FeHelper Timestamp Tools
+ */
+new Vue({
+    el: '#pageContainer',
+    data: {
+        txtNow: Math.round((new Date()).getTime() / 1000),
+        txtNowDate: (new Date()).toLocaleString(),
+        txtSrcStamp: '',
+        txtDesDate: '',
+        txtLocale: '',
+        txtDesStamp: ''
+    },
+    mounted: function () {
+        this.startTimestamp();
+    },
+    methods: {
+        startTimestamp: function () {
+            window.intervalId = window.setInterval(() => {
+                this.txtNowDate = (new Date()).toLocaleString();
+                this.txtNow = Math.round((new Date()).getTime() / 1000);
+            }, 1000);
+        },
+        unixToggle: function () {
+            window.toggleModel = window.toggleModel || 0;
+            if (window.toggleModel) {
+                this.$refs.btnToggle.value = '暂停';
+                window.toggleModel = 0;
+                this.startTimestamp();
+            } else {
+                this.$refs.btnToggle.value = '开始';
+                window.toggleModel = 1;
+                window.clearInterval(window.intervalId);
+            }
+        },
+        stampToLocale: function () {
+            if (this.txtSrcStamp.length === 0) {
+                alert('请先填写你需要转换的Unix时间戳');
+                return;
+            }
+            if (!parseInt(this.txtSrcStamp, 10)) {
+                alert('请输入合法的Unix时间戳');
+                return;
+            }
+            Tarp.require('../static/js/utils');
+            this.txtDesDate = (new Date(parseInt(this.txtSrcStamp, 10) * 1000)).format('yyyy-MM-dd HH:mm:ss');
+        },
+        localeToStamp: function () {
+            let locale = Date.parse(this.txtLocale);
+            if (isNaN(locale)) {
+                alert('请输入合法的时间格式,如:2014-04-01 10:01:01,或:2014-01-01');
+            }
+            this.txtDesStamp = locale / 1000;
+        }
+    }
+});

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff