From f62e1714111f1f4ef72d76107de5f9fd875fac4d Mon Sep 17 00:00:00 2001 From: ybouane Date: Thu, 10 Oct 2024 14:52:13 -0400 Subject: [PATCH] Added link icon for each endpoint --- config.js | 16 ++++++++-------- static/client.js | 7 +++++++ static/index.html | 2 +- static/style.css | 23 +++++++++++++++++++++++ watcher.js | 6 ++++-- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/config.js b/config.js index 4fce19c..a3bc7f8 100644 --- a/config.js +++ b/config.js @@ -35,16 +35,16 @@ export default { endpoints : [ { id : 'homepage', // optional - name : 'Homepage', - link : 'https://www.google.com', // optional (for notifications and dashboard only), [defaults to endpoint.url] - url : 'https://www.google.com', - request : { // fetch options + name : 'Homepage', // optional + link : 'https://www.google.com', // optional, for notifications and dashboard only, [defaults to endpoint.url], can be disabled by settig it to false + url : 'https://www.google.com', // required + request : { // optional, fetch options method: 'GET', }, - mustFind : 'Feeling Lucky', // String | Array | Regex | Function | AsyncFunction - mustNotFind : /Page not found/i, // String | Array | Regex | Function | AsyncFunction - customCheck : async (content, response)=>{return true;}, // Function | AsyncFunction -> Run your own custom checks return false in case of errors - validStatus : [200], // Which http status should be considered non errors [defaults to 200-299] + mustFind : 'Feeling Lucky', // optional, String | Array | Regex | Function | AsyncFunction + mustNotFind : /Page not found/i, // optional, String | Array | Regex | Function | AsyncFunction + customCheck : async (content, response)=>{return true;}, // optional, Function | AsyncFunction -> Run your own custom checks return false in case of errors + validStatus : [200], // optional, Which http status should be considered non errors [defaults to 200-299] } ] } diff --git a/static/client.js b/static/client.js index e12a953..22fde33 100644 --- a/static/client.js +++ b/static/client.js @@ -37,6 +37,13 @@ document.addEventListener("DOMContentLoaded", async () => { $endpointName = document.createElement('h3'); $endpointName.innerText = endpoint.name; + if(endpoint.link) { + let $link = document.createElement('a'); + $link.href = endpoint.link; + $link.target = '_blank'; + $link.innerHTML = 'open_in_new'; + $endpointName.append($link); + } $endpoint.append($endpointName); let $statusBarEndpoint = document.createElement('status-bar'); diff --git a/static/index.html b/static/index.html index 571d1f2..b0e6a99 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ - + diff --git a/static/style.css b/static/style.css index 8659765..2fcc1e2 100644 --- a/static/style.css +++ b/static/style.css @@ -18,6 +18,29 @@ body { padding:40px 20px; min-height:100vh; } +.icon { + font-family: 'Material Symbols Outlined'; + font-weight: normal; + font-style: normal; + line-height: 1; + letter-spacing: normal; + text-transform: none; + display: inline-block; + white-space: nowrap; + word-wrap: normal; + direction: ltr; + -webkit-font-feature-settings: 'liga'; + -webkit-font-smoothing: antialiased; + font-variation-settings: 'FILL' 0, 'wght' 200, 'GRAD' 0, 'opsz' 24; + + font-size:0.85em; + margin:0px 4px; +} + +a:has(>.icon:only-child) { + display:inline-flex; + text-decoration: none; +} a { color:inherit; diff --git a/watcher.js b/watcher.js index 8d38471..1e36581 100644 --- a/watcher.js +++ b/watcher.js @@ -175,6 +175,8 @@ while(true) { site_.endpoints[endpointId] = site_.endpoints[endpointId] || {}; let endpoint_ = site_.endpoints[endpointId]; // shortcut ref endpoint_.name = endpoint.name || endpoint_.name; + if(endpoint.link!==false) + endpoint_.link = endpoint.link || endpoint.url; endpoint_.logs = endpoint_.logs || []; let start; @@ -243,7 +245,7 @@ while(true) { `šŸ”„ ERROR\n`+ `${site.name || siteId} — ${endpoint.name || endpointId} [${endpointStatus.ttfb.toFixed(2)}ms]\n`+ `→ ${endpointStatus.err}`+ - `\n→ ${endpoint.link || endpoint.url}\n` + (endpoint.link!==false?`\n→ ${endpoint.link || endpoint.url}`:'') ); } } catch(e) {console.error(e);} @@ -264,7 +266,7 @@ while(true) { /*await*/ sendNotification( // Don't await to prevent blocking/delaying next pulse `🟄 High Latency\n`+ `${site.name || siteId} — ${endpoint.name || endpointId} [${endpointStatus.ttfb.toFixed(2)}ms]\n`+ - `\n→ ${endpoint.link || endpoint.url}\n` + (endpoint.link!==false?`\n→ ${endpoint.link || endpoint.url}`:'') ); } } catch(e) {console.error(e);}