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