chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { if (request.act === "instances") { showLists(request.instances); } }); chrome.runtime.sendMessage({ act: 'getInstances' }, function (response) { showLists(response); }); function onClick(index) { chrome.runtime.sendMessage({ act: 'clickInstances', index: index, }); } function onDelete(index) { chrome.runtime.sendMessage({ act: 'delInstances', index: index, }); } function showLists(lists) { var html = ''; var j = 1; var length = Object.keys(lists).length; var tempLists = $A.jsonParse($A.getStorage("configLists"), {}); for (var index in lists) { if (!lists.hasOwnProperty(index)) { continue; } if (tempLists[index] === null || typeof tempLists[index] !== "object") { continue; } if (tempLists[index].disabled === true) { continue; } const item = Object.assign(lists[index], { nickname: tempLists[index].nickname, online: tempLists[index].online, }); html+= '
  • '; if (item.nickname) { html+= `
    ${item.nickname} (${item.username})
    `; } else { html+= '
    ' + item.username + '
    '; } html+= '
    ' + index + '
    '; html+= '
    未读: ' + item.unread + '
    '; html+= '
    删除
    '; html+= '
  • '; j++; } if (!html) { html+= '
  • '; html+= '
    没有相关的记录!
    '; html+= '
  • '; } $("#message_div").html(''); $("div.message_delete").click(function(){ if (confirm("确定要删除此记录吗?")) { onDelete($(this).parents("li").attr("data-index")); } }); $("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")); 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 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}); onClick(index); return has = true; } }); if (!has) { chrome.tabs.create({ url: opurl }); onClick(index); } }); }) }