Explorar o código

优化chrome插件

kuaifan %!s(int64=5) %!d(string=hai) anos
pai
achega
ca567bc932

+ 31 - 2
resources/notify/chrome/js/base.js

@@ -218,15 +218,44 @@
                 desc = '[文件]';
                 break;
             case 'taskB':
-                desc = content.text + " [来自关注任务]";
+                desc = content.text + " [任务消息]";
                 break;
             case 'report':
-                desc = content.text + " [来自工作报告]";
+                desc = content.text + " [工作报告]";
                 break;
             default:
                 desc = '[未知类型]';
                 break;
         }
         return desc;
+    },
+
+    /**
+     * 更新参数
+     * @param key
+     * @param updateConfig
+     */
+    updateConfigLists(key, updateConfig) {
+        var configLists = $A.jsonParse($A.getStorage("configLists"), {});
+        var keyConfig = configLists[key];
+        if (keyConfig !== null
+            && typeof keyConfig == "object"
+            && updateConfig !== null
+            && typeof updateConfig == "object") {
+            var up = false;
+            for (var k in updateConfig) {
+                if (!updateConfig.hasOwnProperty(k)) {
+                    continue;
+                }
+                if (updateConfig[k] !== keyConfig[k]) {
+                    up = true;
+                    break;
+                }
+            }
+            if (up) {
+                keyConfig = Object.assign(keyConfig, updateConfig);
+                $A.setStorage("configLists", $A.jsonStringify(configLists));
+            }
+        }
     }
 }

+ 3 - 5
resources/notify/chrome/js/options.js

@@ -18,10 +18,8 @@ if (html == '') {
     $("#lists").html('没有相关的记录!');
 } else {
     $("input[class=checkbox]").on('change', function () {
-        var tempLists = $A.jsonParse($A.getStorage("configLists"), {});
-        if (typeof tempLists[$(this).attr("name")] == "object") {
-            tempLists[$(this).attr("name")]["disabled"] = $(this).is(':checked');
-            $A.setStorage("configLists", $A.jsonStringify(tempLists));
-        }
+        $A.updateConfigLists($(this).attr("name"), {
+            disabled: $(this).is(':checked')
+        });
     });
 }

+ 13 - 5
resources/notify/chrome/js/popup.js

@@ -40,7 +40,8 @@ function showLists(lists) {
             continue;
         }
         const item = Object.assign(lists[index], {
-            nickname: tempLists[index].nickname
+            nickname: tempLists[index].nickname,
+            online: tempLists[index].online,
         });
         html+= '<li class="message_box' + (j == length ? ' last' : '') + '" data-index="' + index + '" data-token="' + item.token + '">';
         if (item.nickname) {
@@ -49,7 +50,7 @@ function showLists(lists) {
             html+= '<div class="message_username">' + item.username + '</div>';
         }
         html+= '<div class="message_host">' + index + '</div>';
-        html+= '<div class="message_unread' + (item.unread == 0 ? ' zero' : '') + '">未读: ' + item.unread + '</div>';
+        html+= '<div class="message_unread' + (item.unread == 0 ? ' zero' : '') + '' + (item.online === true ? '' : ' offline') + '">未读: ' + item.unread + '</div>';
         html+= '<div class="message_delete">删除</div>';
         html+= '</li>';
         j++;
@@ -65,15 +66,22 @@ function showLists(lists) {
             onDelete($(this).parents("li").attr("data-index"));
         }
     });
-    $("div.message_unread,div.message_host").click(function(){
+    $("div.message_unread,div.message_username,div.message_host").click(function(e){
         const index = $(this).parents("li").attr("data-index");
         const token = encodeURIComponent($(this).parents("li").attr("data-token"));
-        const opurl = 'http://' + index + '/todo?token=' + token + '&open=chat';
+        var opurl = 'http://' + index + '/todo?token=' + token;
+        if (e.target.className == 'message_unread') {
+            opurl+= '&open=chat'
+        }
         chrome.tabs.query({}, function (tabs) {
             var has = false;
             tabs.some(function (item) {
                 if ($A.getHost(item.url) == index) {
-                    var url = $A.getPathname(item.url) == '/' ? opurl : ($A.urlAddParams($A.removeURLParameter(item.url, ['open', 'rand']), {open: 'chat', rand: Math.round(new Date().getTime())}))
+                    var params = {rand: Math.round(new Date().getTime())};
+                    if (e.target.className == 'message_unread') {
+                        params.open = 'chat';
+                    }
+                    var url = $A.getPathname(item.url) == '/' ? opurl : ($A.urlAddParams($A.removeURLParameter(item.url, ['open', 'rand']), params))
                     chrome.windows.update(item.windowId, {focused: true});
                     chrome.tabs.highlight({tabs: item.index, windowId: item.windowId});
                     chrome.tabs.update({url: url});

+ 9 - 0
resources/notify/chrome/js/wtws.js

@@ -176,6 +176,9 @@ const WTWS = function (config) {
                 thas.sendTo('roger', msgDetail.contentId);
             }
             thas.triggerMsgListener(msgDetail);
+            $A.updateConfigLists(thas.__config.key, {
+                online: true
+            });
         };
 
         // 连接关闭时触发
@@ -184,6 +187,9 @@ const WTWS = function (config) {
             thas.__connected = false;
             thas.__instance = null;
             thas.__autoLine(5);
+            $A.updateConfigLists(thas.__config.key, {
+                online: false
+            });
         }
 
         // 连接出错
@@ -192,6 +198,9 @@ const WTWS = function (config) {
             thas.__connected = false;
             thas.__instance = null;
             thas.__autoLine(5);
+            $A.updateConfigLists(thas.__config.key, {
+                online: false
+            });
         }
 
         return this;

+ 1 - 1
resources/notify/chrome/manifest.json

@@ -1,6 +1,6 @@
 {
     "manifest_version": 2,
-    "version": "1.3",
+    "version": "1.4",
     "name": "TEAM提醒",
     "description": "TEAM消息提醒",
     "icons": {

+ 5 - 0
resources/notify/chrome/popup.html

@@ -50,6 +50,7 @@
             font-size: 16px;
             font-weight: 600;
             margin-bottom: 8px;
+            cursor: pointer;
         }
 
         .message_host {
@@ -89,6 +90,10 @@
             background-color: #2196F3;
         }
 
+        .message_unread.offline {
+            background-color: #bfbfbf;
+        }
+
         .message_delete {
             position: absolute;
             bottom: 6px;