From e0442de726e471a8e085f477e95622edfd01512d Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 15 Apr 2024 23:58:19 +0800 Subject: [PATCH] add hero list --- public/index.html | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/public/index.html b/public/index.html index 375cc2e..770969e 100644 --- a/public/index.html +++ b/public/index.html @@ -14,6 +14,8 @@ small{font-size:65%;font-weight:400} pre{background-color:#DDD;padding-bottom:3px;padding-right:3px;border-radius:0 5px 0 5px;max-width:480px} code{display:block;background-color:#EEE;padding:4px} + dt{background-color:#EEE;padding:4px 6px} + dd{text-indent:1em;margin:4px 0 8px 0} .text-center{text-align:center} .mt-d5{margin-top:0.5em} @@ -95,6 +97,18 @@

JSON数据

...
+

爬虫列表

+
+ +
+ + @@ -120,6 +134,33 @@ } }; + var htmlspecialchars = function(str) { + return str.replace('&', '&').replace('<', '<').replace('>', '>'); + }; + + var renderHeros = function(heros) { + if (!heros || heros.length == 0) { + $('#herobots').text('暂无爬虫加入联盟。'); + return; + } + + var txtStatus = {idle: '空闲', busy: '繁忙', offline: '离线'}; + var html = '', item; + for (var index in heros) { + item = heros[index]; + html += '
' + htmlspecialchars(item['name']) + ' ' + + txtStatus[item['status']] + '
'; + html += '
' + + htmlspecialchars(item['description']) + + ',支持:' + JSON.stringify(item['platforms']) + + ',合约:' + JSON.stringify(item['contracts']) + + ',联系:' + htmlspecialchars(item['contact']) + + '
'; + } + + $('#herobots').html(html); + }; + var api = '/api/stats/'; $.ajax({ url: api, @@ -131,6 +172,15 @@ renderStats(data.taskStatus); renderStats(data.heroStatus); }); + + api = '/api/heros/'; + $.ajax({ + url: api, + method: 'GET', + dataType: 'json' + }).done(function(data) { + renderHeros(data); + }); \ No newline at end of file