diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-03-03 01:03:29 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-03 01:03:29 +0900 |
| commit | 5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e (patch) | |
| tree | 246d32546b846566e3dcbd324cd4054cd9a733b9 /src/server/web/cli.js | |
| parent | wip: better error handling (diff) | |
| download | misskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.tar.gz misskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.tar.bz2 misskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.zip | |
Bios (#7286)
* wip
* wip
* wip
Diffstat (limited to '')
| -rw-r--r-- | src/server/web/cli.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/web/cli.js b/src/server/web/cli.js new file mode 100644 index 0000000000..3dff1d4860 --- /dev/null +++ b/src/server/web/cli.js @@ -0,0 +1,55 @@ +'use strict'; + +window.onload = async () => { + const account = JSON.parse(localStorage.getItem('account')); + const i = account.token; + + const api = (endpoint, data = {}) => { + const promise = new Promise((resolve, reject) => { + // Append a credential + if (i) data.i = i; + + // Send request + fetch(endpoint.indexOf('://') > -1 ? endpoint : `/api/${endpoint}`, { + method: 'POST', + body: JSON.stringify(data), + credentials: 'omit', + cache: 'no-cache' + }).then(async (res) => { + const body = res.status === 204 ? null : await res.json(); + + if (res.status === 200) { + resolve(body); + } else if (res.status === 204) { + resolve(); + } else { + reject(body.error); + } + }).catch(reject); + }); + + return promise; + }; + + document.getElementById('submit').addEventListener('click', () => { + api('notes/create', { + text: document.getElementById('text').value + }).then(() => { + location.reload(); + }); + }); + + api('notes/timeline').then(notes => { + const tl = document.getElementById('tl'); + for (const note of notes) { + const el = document.createElement('div'); + const name = document.createElement('header'); + name.textContent = `${note.user.name} @${note.user.username}`; + const text = document.createElement('div'); + text.textContent = `${note.text}`; + el.appendChild(name); + el.appendChild(text); + tl.appendChild(el); + } + }); +}; |