summaryrefslogtreecommitdiff
path: root/src/server/web/bios.js
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-03-03 01:03:29 +0900
committerGitHub <noreply@github.com>2021-03-03 01:03:29 +0900
commit5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e (patch)
tree246d32546b846566e3dcbd324cd4054cd9a733b9 /src/server/web/bios.js
parentwip: better error handling (diff)
downloadmisskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.tar.gz
misskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.tar.bz2
misskey-5e9cc09fcb6cb88cc4d2c3040bf085e9e278d22e.zip
Bios (#7286)
* wip * wip * wip
Diffstat (limited to 'src/server/web/bios.js')
-rw-r--r--src/server/web/bios.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/server/web/bios.js b/src/server/web/bios.js
new file mode 100644
index 0000000000..d06dee801a
--- /dev/null
+++ b/src/server/web/bios.js
@@ -0,0 +1,87 @@
+'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;
+ };
+
+ const content = document.getElementById('content');
+
+ document.getElementById('ls').addEventListener('click', () => {
+ content.innerHTML = '';
+
+ const lsEditor = document.createElement('div');
+ lsEditor.id = 'lsEditor';
+
+ const adder = document.createElement('div');
+ adder.classList.add('adder');
+ const addKeyInput = document.createElement('input');
+ const addValueTextarea = document.createElement('textarea');
+ const addButton = document.createElement('button');
+ addButton.textContent = 'add';
+ addButton.addEventListener('click', () => {
+ localStorage.setItem(addKeyInput.value, addValueTextarea.value);
+ location.reload();
+ });
+
+ adder.appendChild(addKeyInput);
+ adder.appendChild(addValueTextarea);
+ adder.appendChild(addButton);
+ lsEditor.appendChild(adder);
+
+ for (let i = 0; i < localStorage.length; i++) {
+ const k = localStorage.key(i);
+ const record = document.createElement('div');
+ record.classList.add('record');
+ const header = document.createElement('header');
+ header.textContent = k;
+ const textarea = document.createElement('textarea');
+ textarea.textContent = localStorage.getItem(k);
+ const saveButton = document.createElement('button');
+ saveButton.textContent = 'save';
+ saveButton.addEventListener('click', () => {
+ localStorage.setItem(k, textarea.value);
+ location.reload();
+ });
+ const removeButton = document.createElement('button');
+ removeButton.textContent = 'remove';
+ removeButton.addEventListener('click', () => {
+ localStorage.removeItem(k);
+ location.reload();
+ });
+ record.appendChild(header);
+ record.appendChild(textarea);
+ record.appendChild(saveButton);
+ record.appendChild(removeButton);
+ lsEditor.appendChild(record);
+ }
+
+ content.appendChild(lsEditor);
+ });
+};