2023-07-27 08:31:52 +03:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-03-02 18:03:29 +02:00
|
|
|
'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;
|
2023-07-08 01:08:16 +03:00
|
|
|
|
2021-03-02 18:03:29 +02:00
|
|
|
// Send request
|
|
|
|
fetch(endpoint.indexOf('://') > -1 ? endpoint : `/api/${endpoint}`, {
|
2023-02-12 01:21:13 +02:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
2021-03-02 18:03:29 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
credentials: 'omit',
|
|
|
|
cache: 'no-cache'
|
|
|
|
}).then(async (res) => {
|
|
|
|
const body = res.status === 204 ? null : await res.json();
|
2023-07-08 01:08:16 +03:00
|
|
|
|
2021-03-02 18:03:29 +02:00
|
|
|
if (res.status === 200) {
|
|
|
|
resolve(body);
|
|
|
|
} else if (res.status === 204) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject(body.error);
|
|
|
|
}
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
2023-07-08 01:08:16 +03:00
|
|
|
|
2021-03-02 18:03:29 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|