| 1 | /* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */ |
| 2 | #ifndef SX_TIME_UI_HTML_H |
| 3 | #define SX_TIME_UI_HTML_H |
| 4 | |
| 5 | static const char *UI_HTML = |
| 6 | "<!DOCTYPE html>\n" |
| 7 | "<html lang=\"en\"><head><meta charset=\"utf-8\">\n" |
| 8 | "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n" |
| 9 | "<title>time</title>\n" |
| 10 | "\001\n" |
| 11 | "<style>\n" |
| 12 | "*{box-sizing:border-box}\n" |
| 13 | "html,body{margin:0}\n" |
| 14 | "body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;\n" |
| 15 | " line-height:1.5;-webkit-font-smoothing:antialiased}\n" |
| 16 | ".wrap{max-width:1080px;margin:0 auto;padding:16px}\n" |
| 17 | "h1{font-size:20px;margin:0 0 2px;font-weight:650;letter-spacing:-.01em}\n" |
| 18 | ".sub{color:var(--mu);font-size:12.5px;margin-bottom:14px}\n" |
| 19 | ".card{background:var(--surface);border:1px solid var(--ln);border-radius:14px;\n" |
| 20 | " padding:16px;margin-bottom:14px}\n" |
| 21 | ".card h2{font-size:13px;font-weight:650;margin:0 0 12px;color:var(--mu);\n" |
| 22 | " text-transform:uppercase;letter-spacing:.06em}\n" |
| 23 | ".row{display:flex;flex-wrap:wrap;gap:10px;align-items:flex-end}\n" |
| 24 | "label{display:block;font-size:11.5px;color:var(--mu);margin-bottom:4px;\n" |
| 25 | " text-transform:uppercase;letter-spacing:.05em}\n" |
| 26 | "input,select{background:var(--input-bg);border:1px solid var(--ln);color:var(--text);\n" |
| 27 | " border-radius:9px;padding:7px 10px;font-size:13.5px;font-family:var(--font);\n" |
| 28 | " outline:none;min-width:0}\n" |
| 29 | "input:focus,select:focus{border-color:var(--ac)}\n" |
| 30 | "select{cursor:pointer}\n" |
| 31 | "input[type=time]{font-family:var(--mono)}\n" |
| 32 | "button{background:var(--ac);color:#fff;border:0;border-radius:980px;padding:7px 16px;\n" |
| 33 | " font-size:13px;font-weight:600;cursor:pointer;font-family:var(--font)}\n" |
| 34 | "button.ghost{background:var(--surface-2);color:var(--text)}\n" |
| 35 | "button:active{transform:scale(.98)}\n" |
| 36 | ".clock{display:grid;grid-template-columns:1fr auto;gap:12px;align-items:center}\n" |
| 37 | ".time{font-family:var(--mono);font-size:44px;font-weight:600;letter-spacing:-.03em;\n" |
| 38 | " line-height:1.05;font-variant-numeric:tabular-nums}\n" |
| 39 | "@media(max-width:640px){.time{font-size:32px}}\n" |
| 40 | ".zone{font-size:13px;color:var(--mu);margin-top:2px}\n" |
| 41 | ".badge{display:inline-block;font-size:11px;font-weight:600;padding:2px 9px;\n" |
| 42 | " border-radius:980px;border:1px solid var(--ln);color:var(--mu);\n" |
| 43 | " background:var(--surface-2);margin-left:6px;vertical-align:middle}\n" |
| 44 | ".badge.dst{color:var(--orange);border-color:rgba(255,159,10,.35)}\n" |
| 45 | ".badge.std{color:var(--green);border-color:rgba(48,209,88,.3)}\n" |
| 46 | "table{width:100%;border-collapse:collapse;font-size:13px}\n" |
| 47 | "th{text-align:left;font-size:11px;color:var(--mu);text-transform:uppercase;\n" |
| 48 | " letter-spacing:.05em;font-weight:600;padding:0 8px 7px 0;border-bottom:1px solid var(--ln)}\n" |
| 49 | "td{padding:8px 8px 8px 0;border-bottom:1px solid var(--ln);vertical-align:middle}\n" |
| 50 | "tr:last-child td{border-bottom:0}\n" |
| 51 | "td.t{font-family:var(--mono);font-variant-numeric:tabular-nums;white-space:nowrap}\n" |
| 52 | "td.n{font-weight:600}\n" |
| 53 | ".tbl-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch}\n" |
| 54 | ".out{margin-top:14px;padding:14px;border-radius:12px;background:var(--code-bg);\n" |
| 55 | " font-family:var(--mono);font-size:12.5px;white-space:pre-wrap;word-break:break-word;\n" |
| 56 | " color:var(--text);display:none}\n" |
| 57 | ".out.on{display:block}\n" |
| 58 | ".out.err{color:var(--red)}\n" |
| 59 | ".conv{display:grid;grid-template-columns:1fr auto 1fr;gap:12px;align-items:end}\n" |
| 60 | ".arrow{font-size:18px;color:var(--mu);padding-bottom:9px}\n" |
| 61 | ".conv-out{margin-top:14px;display:none}\n" |
| 62 | ".conv-out.on{display:block}\n" |
| 63 | ".big{font-family:var(--mono);font-size:26px;font-weight:600;letter-spacing:-.02em;\n" |
| 64 | " font-variant-numeric:tabular-nums}\n" |
| 65 | ".pair{display:grid;grid-template-columns:1fr 1fr;gap:12px}\n" |
| 66 | ".mini{background:var(--surface-2);border-radius:11px;padding:12px}\n" |
| 67 | ".mini .lbl{font-size:11px;color:var(--mu);text-transform:uppercase;letter-spacing:.05em}\n" |
| 68 | ".note{margin-top:12px;padding:11px 13px;border-radius:10px;\n" |
| 69 | " background:rgba(255,159,10,.1);border:1px solid rgba(255,159,10,.3);\n" |
| 70 | " font-size:12.5px;color:var(--text);display:none}\n" |
| 71 | ".note.on{display:block}\n" |
| 72 | ".err-msg{margin-top:12px;color:var(--red);font-size:12.5px;display:none}\n" |
| 73 | ".err-msg.on{display:block}\n" |
| 74 | ".add{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:12px}\n" |
| 75 | ".add select{flex:1 1 220px}\n" |
| 76 | ".foot{color:var(--mu);font-size:11.5px;margin-top:2px}\n" |
| 77 | "kbd{font-family:var(--mono);font-size:11px;background:var(--surface-2);\n" |
| 78 | " border:1px solid var(--ln);border-radius:5px;padding:1px 5px}\n" |
| 79 | "@media(max-width:640px){\n" |
| 80 | " .conv{grid-template-columns:1fr;}\n" |
| 81 | " .arrow{display:none}\n" |
| 82 | " .pair{grid-template-columns:1fr}\n" |
| 83 | " .clock{grid-template-columns:1fr}\n" |
| 84 | " /* A phone cannot hold six columns: the weekday is derivable from the date,\n" |
| 85 | " * so it is the one that goes. Everything else stays, unscrolled, and the\n" |
| 86 | " * Remove button shrinks to a glyph. */\n" |
| 87 | " /* The header cells live in <thead>, not inside #grid, so the selector has\n" |
| 88 | " * to reach the table, not the tbody - otherwise the header keeps a column\n" |
| 89 | " * the rows have dropped and the widths fight. */\n" |
| 90 | " /* Two columns go: the weekday is derivable from the date, and the offset is\n" |
| 91 | " * the one thing a 390 px reader can live without on the wide view. What is\n" |
| 92 | " * left - zone, time, date, Remove - fits without a horizontal scroll, so the\n" |
| 93 | " * Remove button can never be clipped. */\n" |
| 94 | " .tbl-wrap th:nth-child(4),.tbl-wrap td:nth-child(4),\n" |
| 95 | " .tbl-wrap th:nth-child(5),.tbl-wrap td:nth-child(5){display:none}\n" |
| 96 | " .tbl-wrap table{font-size:12px}\n" |
| 97 | " .tbl-wrap th,.tbl-wrap td{padding:7px 6px 7px 0}\n" |
| 98 | " .tbl-wrap button{padding:3px 8px!important;font-size:10.5px!important}\n" |
| 99 | " .card{padding:13px}\n" |
| 100 | " .wrap{padding:12px}\n" |
| 101 | "}\n" |
| 102 | "</style>\n" |
| 103 | "</head><body>\n" |
| 104 | "<div class=\"wrap\">\n" |
| 105 | " <h1>World time</h1>\n" |
| 106 | " <div class=\"sub\">IANA timezones resolved from the database embedded in this plugin, so every node answers identically.</div>\n" |
| 107 | "\n" |
| 108 | " <div class=\"card\">\n" |
| 109 | " <h2>Clock</h2>\n" |
| 110 | " <div class=\"clock\">\n" |
| 111 | " <div>\n" |
| 112 | " <div class=\"time\" id=\"clock\">--:--:--</div>\n" |
| 113 | " <div class=\"zone\"><span id=\"clockZone\">-</span><span class=\"badge\" id=\"clockBadge\"></span></div>\n" |
| 114 | " </div>\n" |
| 115 | " <div>\n" |
| 116 | " <label for=\"clockSel\">Zone</label>\n" |
| 117 | " <select id=\"clockSel\"></select>\n" |
| 118 | " </div>\n" |
| 119 | " </div>\n" |
| 120 | " <div class=\"err-msg\" id=\"clockErr\"></div>\n" |
| 121 | " </div>\n" |
| 122 | "\n" |
| 123 | " <div class=\"card\">\n" |
| 124 | " <h2>Convert a time</h2>\n" |
| 125 | " <div class=\"conv\">\n" |
| 126 | " <div>\n" |
| 127 | " <label for=\"convFrom\">From</label>\n" |
| 128 | " <select id=\"convFrom\"></select>\n" |
| 129 | " </div>\n" |
| 130 | " <div class=\"arrow\">→</div>\n" |
| 131 | " <div>\n" |
| 132 | " <label for=\"convTo\">To</label>\n" |
| 133 | " <select id=\"convTo\"></select>\n" |
| 134 | " </div>\n" |
| 135 | " </div>\n" |
| 136 | " <div class=\"row\" style=\"margin-top:12px\">\n" |
| 137 | " <div>\n" |
| 138 | " <label for=\"convTime\">Time (24h)</label>\n" |
| 139 | " <input type=\"time\" id=\"convTime\" value=\"09:00\" step=\"60\">\n" |
| 140 | " </div>\n" |
| 141 | " <button id=\"convBtn\" type=\"button\">Convert</button>\n" |
| 142 | " </div>\n" |
| 143 | " <div class=\"conv-out\" id=\"convOut\">\n" |
| 144 | " <div class=\"pair\">\n" |
| 145 | " <div class=\"mini\"><div class=\"lbl\">Source</div><div class=\"big\" id=\"convSrc\">-</div>\n" |
| 146 | " <div class=\"zone\" id=\"convSrcZone\"></div></div>\n" |
| 147 | " <div class=\"mini\"><div class=\"lbl\">Target</div><div class=\"big\" id=\"convDst\">-</div>\n" |
| 148 | " <div class=\"zone\" id=\"convDstZone\"></div></div>\n" |
| 149 | " </div>\n" |
| 150 | " <div class=\"foot\" id=\"convDiff\" style=\"margin-top:10px\"></div>\n" |
| 151 | " <div class=\"note\" id=\"convNote\"></div>\n" |
| 152 | " <div class=\"err-msg\" id=\"convErr\"></div>\n" |
| 153 | " </div>\n" |
| 154 | " </div>\n" |
| 155 | "\n" |
| 156 | " <div class=\"card\">\n" |
| 157 | " <h2>World clock</h2>\n" |
| 158 | " <div class=\"add\">\n" |
| 159 | " <select id=\"addSel\"></select>\n" |
| 160 | " <button class=\"ghost\" id=\"addBtn\" type=\"button\">Add zone</button>\n" |
| 161 | " <button class=\"ghost\" id=\"resetBtn\" type=\"button\">Reset</button>\n" |
| 162 | " </div>\n" |
| 163 | " <div class=\"tbl-wrap\">\n" |
| 164 | " <table>\n" |
| 165 | " <colgroup><col><col style=\"width:74px\"><col style=\"width:86px\"><col><col style=\"width:62px\"><col style=\"width:62px\"></colgroup>\n" |
| 166 | " <thead><tr><th>Zone</th><th>Time</th><th>Date</th><th>Day</th><th>Offset</th><th></th></tr></thead>\n" |
| 167 | " <tbody id=\"grid\"></tbody>\n" |
| 168 | " </table>\n" |
| 169 | " </div>\n" |
| 170 | " <div class=\"foot\" style=\"margin-top:10px\">Times refresh every second from the tool itself, not from your browser's clock.</div>\n" |
| 171 | " </div>\n" |
| 172 | "\n" |
| 173 | " <div class=\"card\">\n" |
| 174 | " <h2>Time ago</h2>\n" |
| 175 | " <div class=\"row\">\n" |
| 176 | " <div><label for=\"agoD\">Days</label><input type=\"number\" id=\"agoD\" value=\"1\" min=\"0\" style=\"width:82px\"></div>\n" |
| 177 | " <div><label for=\"agoH\">Hours</label><input type=\"number\" id=\"agoH\" value=\"0\" min=\"0\" style=\"width:82px\"></div>\n" |
| 178 | " <div><label for=\"agoM\">Minutes</label><input type=\"number\" id=\"agoM\" value=\"0\" min=\"0\" style=\"width:82px\"></div>\n" |
| 179 | " <div><label for=\"agoS\">Seconds</label><input type=\"number\" id=\"agoS\" value=\"0\" min=\"0\" style=\"width:82px\"></div>\n" |
| 180 | " <div><label for=\"agoZone\">Zone</label><select id=\"agoZone\"></select></div>\n" |
| 181 | " <button id=\"agoBtn\" type=\"button\">Compute</button>\n" |
| 182 | " </div>\n" |
| 183 | " <div class=\"out\" id=\"agoOut\"></div>\n" |
| 184 | " <div class=\"err-msg\" id=\"agoErr\"></div>\n" |
| 185 | " </div>\n" |
| 186 | "\n" |
| 187 | " <div class=\"card\">\n" |
| 188 | " <h2>MCP tools</h2>\n" |
| 189 | " <div class=\"out on\" id=\"toolsOut\">Loading...</div>\n" |
| 190 | " </div>\n" |
| 191 | "</div>\n" |
| 192 | "<script>\n" |
| 193 | "(function () {\n" |
| 194 | " var HUB = '';\n" |
| 195 | " try {\n" |
| 196 | " var q0 = new URLSearchParams(location.search);\n" |
| 197 | " HUB = q0.get('plugin') || '';\n" |
| 198 | " } catch (e) {}\n" |
| 199 | "\n" |
| 200 | " function pwd() {\n" |
| 201 | " try {\n" |
| 202 | " var q = new URLSearchParams(location.search);\n" |
| 203 | " return q.get('pwd') || localStorage.getItem('bot_active_pwd') || '';\n" |
| 204 | " } catch (e) { return ''; }\n" |
| 205 | " }\n" |
| 206 | "\n" |
| 207 | " /* Two routes, and getting this wrong is the classic plugin bug:\n" |
| 208 | " * - served through the hub (/plugins?plugin=time&node=...) -> call back\n" |
| 209 | " * through the hub proxy with ?plugin=\n" |
| 210 | " * - opened directly on the node -> the plugin IS the route, /plugin_time\n" |
| 211 | " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n" |
| 212 | " function api(action, params) {\n" |
| 213 | " var q = new URLSearchParams(location.search);\n" |
| 214 | " var node = q.get('node') || '';\n" |
| 215 | " var sid = q.get('id') || '';\n" |
| 216 | " var u = HUB ? ('/plugins?plugin=' + encodeURIComponent(HUB) + '&action=' + encodeURIComponent(action))\n" |
| 217 | " : ('/plugin_time?action=' + encodeURIComponent(action));\n" |
| 218 | " if (node) u += '&node=' + encodeURIComponent(node);\n" |
| 219 | " if (sid) u += '&id=' + encodeURIComponent(sid);\n" |
| 220 | " var p = pwd();\n" |
| 221 | " if (p) u += '&pwd=' + encodeURIComponent(p);\n" |
| 222 | " if (params) {\n" |
| 223 | " Object.keys(params).forEach(function (k) {\n" |
| 224 | " if (params[k] !== '' && params[k] !== null && params[k] !== undefined)\n" |
| 225 | " u += '&' + encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);\n" |
| 226 | " });\n" |
| 227 | " }\n" |
| 228 | " return fetch(u, { headers: p ? { 'X-Bot-Password': p } : {} })\n" |
| 229 | " .then(function (r) { return r.json(); });\n" |
| 230 | " }\n" |
| 231 | "\n" |
| 232 | " var ZONES = [];\n" |
| 233 | " var LOCAL = 'UTC';\n" |
| 234 | " var DEFAULT_WORLD = ['Pacific/Auckland', 'Australia/Sydney', 'Asia/Tokyo',\n" |
| 235 | " 'Asia/Kolkata', 'Europe/London', 'Europe/Berlin',\n" |
| 236 | " 'America/New_York', 'America/Los_Angeles', 'UTC'];\n" |
| 237 | " var world = [];\n" |
| 238 | " var clockZone = '';\n" |
| 239 | "\n" |
| 240 | " function byId(id) { return document.getElementById(id); }\n" |
| 241 | "\n" |
| 242 | " function el(tag, cls, text) {\n" |
| 243 | " var e = document.createElement(tag);\n" |
| 244 | " if (cls) e.className = cls;\n" |
| 245 | " if (text !== undefined) e.textContent = text;\n" |
| 246 | " return e;\n" |
| 247 | " }\n" |
| 248 | "\n" |
| 249 | " function fillSelect(sel, value, only) {\n" |
| 250 | " sel.innerHTML = '';\n" |
| 251 | " var list = only || ZONES;\n" |
| 252 | " list.forEach(function (z) {\n" |
| 253 | " var o = el('option', null, z);\n" |
| 254 | " o.value = z;\n" |
| 255 | " if (z === value) o.selected = true;\n" |
| 256 | " sel.appendChild(o);\n" |
| 257 | " });\n" |
| 258 | " }\n" |
| 259 | "\n" |
| 260 | " function showErr(id, msg) {\n" |
| 261 | " var e = byId(id);\n" |
| 262 | " if (!msg) { e.className = 'err-msg'; e.textContent = ''; return; }\n" |
| 263 | " e.className = 'err-msg on';\n" |
| 264 | " e.textContent = msg;\n" |
| 265 | " }\n" |
| 266 | "\n" |
| 267 | " function fmtOffset(iso) {\n" |
| 268 | " var m = /([+-]\\d\\d:\\d\\d)$/.exec(iso || '');\n" |
| 269 | " return m ? m[1] : '';\n" |
| 270 | " }\n" |
| 271 | "\n" |
| 272 | " function hhmm(iso) {\n" |
| 273 | " var m = /T(\\d\\d:\\d\\d:\\d\\d)/.exec(iso || '');\n" |
| 274 | " return m ? m[1] : '';\n" |
| 275 | " }\n" |
| 276 | "\n" |
| 277 | " function dateOf(iso) {\n" |
| 278 | " var m = /^(\\d{4}-\\d\\d-\\d\\d)/.exec(iso || '');\n" |
| 279 | " return m ? m[1] : '';\n" |
| 280 | " }\n" |
| 281 | "\n" |
| 282 | " /* The clock asks the tool, not the browser: a node whose own clock is off\n" |
| 283 | " * must show the tool's answer, and this also proves the tool is live. */\n" |
| 284 | " function tickClock() {\n" |
| 285 | " api('current', { timezone: clockZone })\n" |
| 286 | " .then(function (d) {\n" |
| 287 | " if (!d || !d.ok) { showErr('clockErr', (d && d.error) || 'Could not read the time.'); return; }\n" |
| 288 | " showErr('clockErr', '');\n" |
| 289 | " byId('clock').textContent = hhmm(d.datetime);\n" |
| 290 | " byId('clockZone').textContent = d.timezone + ' \\u00b7 ' + (d.abbreviation || '') +\n" |
| 291 | " ' \\u00b7 ' + (d.utc_offset || fmtOffset(d.datetime));\n" |
| 292 | " var b = byId('clockBadge');\n" |
| 293 | " b.textContent = d.is_dst ? 'DST' : 'Standard';\n" |
| 294 | " b.className = 'badge ' + (d.is_dst ? 'dst' : 'std');\n" |
| 295 | " })\n" |
| 296 | " .catch(function (e) { showErr('clockErr', String(e)); });\n" |
| 297 | " }\n" |
| 298 | "\n" |
| 299 | " function renderWorld() {\n" |
| 300 | " var tb = byId('grid');\n" |
| 301 | " tb.innerHTML = '';\n" |
| 302 | " if (!world.length) {\n" |
| 303 | " var tr = el('tr');\n" |
| 304 | " var td = el('td', null, 'No zones yet - add one above.');\n" |
| 305 | " td.colSpan = 6;\n" |
| 306 | " td.style.color = 'var(--mu)';\n" |
| 307 | " tr.appendChild(td);\n" |
| 308 | " tb.appendChild(tr);\n" |
| 309 | " return;\n" |
| 310 | " }\n" |
| 311 | " world.forEach(function (z) {\n" |
| 312 | " var tr = el('tr');\n" |
| 313 | " tr.dataset.zone = z;\n" |
| 314 | " var c1 = el('td', 'n', z);\n" |
| 315 | " var c2 = el('td', 't', '--:--:--');\n" |
| 316 | " var c3 = el('td', 't', '');\n" |
| 317 | " var c4 = el('td', '', '');\n" |
| 318 | " var c5 = el('td', 't', '');\n" |
| 319 | " var c6 = el('td');\n" |
| 320 | " var rm = el('button', 'ghost', 'Remove');\n" |
| 321 | " rm.type = 'button';\n" |
| 322 | " rm.style.padding = '3px 11px';\n" |
| 323 | " rm.style.fontSize = '11.5px';\n" |
| 324 | " rm.onclick = function () {\n" |
| 325 | " world = world.filter(function (x) { return x !== z; });\n" |
| 326 | " saveWorld();\n" |
| 327 | " renderWorld();\n" |
| 328 | " };\n" |
| 329 | " c6.appendChild(rm);\n" |
| 330 | " tr.appendChild(c1); tr.appendChild(c2); tr.appendChild(c3);\n" |
| 331 | " tr.appendChild(c4); tr.appendChild(c5); tr.appendChild(c6);\n" |
| 332 | " tb.appendChild(tr);\n" |
| 333 | " });\n" |
| 334 | " tickWorld();\n" |
| 335 | " }\n" |
| 336 | "\n" |
| 337 | " function tickWorld() {\n" |
| 338 | " if (!world.length) return;\n" |
| 339 | " var pending = world.length;\n" |
| 340 | " world.forEach(function (z) {\n" |
| 341 | " api('current', { timezone: z })\n" |
| 342 | " .then(function (d) {\n" |
| 343 | " var tr = byId('grid').querySelector('tr[data-zone=\"' + z.replace(/\"/g, '\\\\\"') + '\"]');\n" |
| 344 | " if (tr && d && d.ok) {\n" |
| 345 | " tr.children[1].textContent = hhmm(d.datetime);\n" |
| 346 | " tr.children[2].textContent = dateOf(d.datetime);\n" |
| 347 | " tr.children[3].textContent = d.day_of_week || '';\n" |
| 348 | " tr.children[4].textContent = d.utc_offset || fmtOffset(d.datetime);\n" |
| 349 | " tr.children[4].style.color = d.is_dst ? 'var(--orange)' : 'var(--mu)';\n" |
| 350 | " }\n" |
| 351 | " pending--;\n" |
| 352 | " })\n" |
| 353 | " .catch(function () { pending--; });\n" |
| 354 | " });\n" |
| 355 | " }\n" |
| 356 | "\n" |
| 357 | " function saveWorld() {\n" |
| 358 | " try { localStorage.setItem('bot_time_world', JSON.stringify(world)); } catch (e) {}\n" |
| 359 | " }\n" |
| 360 | "\n" |
| 361 | " function loadWorld() {\n" |
| 362 | " var saved = null;\n" |
| 363 | " try { saved = JSON.parse(localStorage.getItem('bot_time_world') || 'null'); } catch (e) {}\n" |
| 364 | " if (saved && saved.length) {\n" |
| 365 | " world = saved.filter(function (z) { return ZONES.indexOf(z) >= 0; });\n" |
| 366 | " }\n" |
| 367 | " if (!world.length) {\n" |
| 368 | " world = DEFAULT_WORLD.filter(function (z) { return ZONES.indexOf(z) >= 0; });\n" |
| 369 | " }\n" |
| 370 | " if (!world.length && ZONES.length) world = [ZONES[0]];\n" |
| 371 | " }\n" |
| 372 | "\n" |
| 373 | " function doConvert() {\n" |
| 374 | " var from = byId('convFrom').value;\n" |
| 375 | " var to = byId('convTo').value;\n" |
| 376 | " var t = byId('convTime').value || '09:00';\n" |
| 377 | " showErr('convErr', '');\n" |
| 378 | " byId('convNote').className = 'note';\n" |
| 379 | " api('convert', { source_timezone: from, target_timezone: to, time: t })\n" |
| 380 | " .then(function (d) {\n" |
| 381 | " if (!d || !d.ok) {\n" |
| 382 | " byId('convOut').className = 'conv-out on';\n" |
| 383 | " byId('convSrc').textContent = t;\n" |
| 384 | " byId('convDst').textContent = '-';\n" |
| 385 | " byId('convDiff').textContent = '';\n" |
| 386 | " showErr('convErr', (d && d.error) || 'Could not convert that time.');\n" |
| 387 | " return;\n" |
| 388 | " }\n" |
| 389 | " byId('convOut').className = 'conv-out on';\n" |
| 390 | " byId('convSrc').textContent = hhmm(d.source.datetime);\n" |
| 391 | " byId('convSrcZone').textContent = d.source.timezone + ' \\u00b7 ' +\n" |
| 392 | " d.source.day_of_week + ' ' + dateOf(d.source.datetime) + ' \\u00b7 ' + d.source.utc_offset;\n" |
| 393 | " byId('convDst').textContent = hhmm(d.target.datetime);\n" |
| 394 | " byId('convDstZone').textContent = d.target.timezone + ' \\u00b7 ' +\n" |
| 395 | " d.target.day_of_week + ' ' + dateOf(d.target.datetime) + ' \\u00b7 ' + d.target.utc_offset;\n" |
| 396 | " byId('convDiff').textContent = 'Difference: ' + d.time_difference;\n" |
| 397 | " if (d.later_occurrence) {\n" |
| 398 | " var n = byId('convNote');\n" |
| 399 | " n.className = 'note on';\n" |
| 400 | " n.textContent = d.later_occurrence.note;\n" |
| 401 | " }\n" |
| 402 | " })\n" |
| 403 | " .catch(function (e) {\n" |
| 404 | " byId('convOut').className = 'conv-out on';\n" |
| 405 | " showErr('convErr', String(e));\n" |
| 406 | " });\n" |
| 407 | " }\n" |
| 408 | "\n" |
| 409 | " function doAgo() {\n" |
| 410 | " var zone = byId('agoZone').value;\n" |
| 411 | " showErr('agoErr', '');\n" |
| 412 | " api('ago', {\n" |
| 413 | " timezone: zone,\n" |
| 414 | " days_ago: byId('agoD').value || '0',\n" |
| 415 | " hours_ago: byId('agoH').value || '0',\n" |
| 416 | " minutes_ago: byId('agoM').value || '0',\n" |
| 417 | " seconds_ago: byId('agoS').value || '0'\n" |
| 418 | " }).then(function (d) {\n" |
| 419 | " var out = byId('agoOut');\n" |
| 420 | " out.className = 'out on';\n" |
| 421 | " if (!d || !d.ok) {\n" |
| 422 | " out.className = 'out on err';\n" |
| 423 | " out.textContent = (d && d.error) || 'Could not compute.';\n" |
| 424 | " return;\n" |
| 425 | " }\n" |
| 426 | " out.className = 'out on';\n" |
| 427 | " out.textContent = d.datetime + '\\n' + d.day_of_week + ' \\u00b7 ' +\n" |
| 428 | " d.timezone + ' \\u00b7 ' + (d.is_dst ? 'DST' : 'standard time');\n" |
| 429 | " }).catch(function (e) {\n" |
| 430 | " var out = byId('agoOut');\n" |
| 431 | " out.className = 'out on err';\n" |
| 432 | " out.textContent = String(e);\n" |
| 433 | " });\n" |
| 434 | " }\n" |
| 435 | "\n" |
| 436 | " function loadTools() {\n" |
| 437 | " api('tools').then(function (d) {\n" |
| 438 | " var out = byId('toolsOut');\n" |
| 439 | " if (!d || !d.ok) { out.textContent = 'Could not read the tool list.'; return; }\n" |
| 440 | " var lines = d.tools.map(function (t) {\n" |
| 441 | " return t.name + ' - ' + t.description;\n" |
| 442 | " });\n" |
| 443 | " out.textContent = lines.join('\\n');\n" |
| 444 | " }).catch(function (e) { byId('toolsOut').textContent = String(e); });\n" |
| 445 | " }\n" |
| 446 | "\n" |
| 447 | " api('zones').then(function (d) {\n" |
| 448 | " if (!d || !d.ok) {\n" |
| 449 | " showErr('clockErr', 'Could not load the timezone list.');\n" |
| 450 | " return;\n" |
| 451 | " }\n" |
| 452 | " ZONES = d.zones || [];\n" |
| 453 | " LOCAL = d.local || 'UTC';\n" |
| 454 | " clockZone = LOCAL;\n" |
| 455 | "\n" |
| 456 | " fillSelect(byId('clockSel'), clockZone);\n" |
| 457 | " fillSelect(byId('convFrom'), LOCAL);\n" |
| 458 | " fillSelect(byId('convTo'), ZONES.indexOf('UTC') >= 0 ? 'UTC' : LOCAL);\n" |
| 459 | " fillSelect(byId('addSel'), 'Asia/Tokyo');\n" |
| 460 | " fillSelect(byId('agoZone'), LOCAL);\n" |
| 461 | "\n" |
| 462 | " byId('clockSel').onchange = function () {\n" |
| 463 | " clockZone = this.value;\n" |
| 464 | " tickClock();\n" |
| 465 | " };\n" |
| 466 | " byId('convBtn').onclick = doConvert;\n" |
| 467 | " byId('convTime').onchange = doConvert;\n" |
| 468 | " byId('convFrom').onchange = doConvert;\n" |
| 469 | " byId('convTo').onchange = doConvert;\n" |
| 470 | " byId('agoBtn').onclick = doAgo;\n" |
| 471 | " byId('addBtn').onclick = function () {\n" |
| 472 | " var z = byId('addSel').value;\n" |
| 473 | " if (z && world.indexOf(z) < 0) { world.push(z); saveWorld(); renderWorld(); }\n" |
| 474 | " };\n" |
| 475 | " byId('resetBtn').onclick = function () {\n" |
| 476 | " world = DEFAULT_WORLD.filter(function (z) { return ZONES.indexOf(z) >= 0; });\n" |
| 477 | " saveWorld();\n" |
| 478 | " renderWorld();\n" |
| 479 | " };\n" |
| 480 | "\n" |
| 481 | " loadWorld();\n" |
| 482 | " renderWorld();\n" |
| 483 | " tickClock();\n" |
| 484 | " doConvert();\n" |
| 485 | " loadTools();\n" |
| 486 | "\n" |
| 487 | " setInterval(tickClock, 1000);\n" |
| 488 | " setInterval(tickWorld, 1000);\n" |
| 489 | " }).catch(function (e) {\n" |
| 490 | " showErr('clockErr', String(e));\n" |
| 491 | " });\n" |
| 492 | "})();\n" |
| 493 | "</script>\n" |
| 494 | "\002</body></html>\n" |
| 495 | ; |
| 496 | |
| 497 | #endif /* SX_TIME_UI_HTML_H */ |