pad

minimal etherpad alternative  https://pad.ce9e.org
git clone https://git.ce9e.org/pad.git

commit
3a1ff4d63ca24a65ae2eef1dcecd974e8e2eea1a
parent
eebf1020c1487478e794e2053b6ec77f0e1f612c
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-11-07 08:22
use async/await

Diffstat

M static/pad.js 29 +++++++++++++----------------

1 files changed, 13 insertions, 16 deletions


diff --git a/static/pad.js b/static/pad.js

@@ -23,14 +23,13 @@ function exit() {
   23    23 	eventSource.close();
   24    24 }
   25    25 
   26    -1 function fetchJSON(res, options) {
   27    -1 	return fetch(res, options).then(response => {
   28    -1 		if (response.ok) {
   29    -1 			return response.json();
   30    -1 		} else {
   31    -1 			throw response;
   32    -1 		}
   33    -1 	});
   -1    26 async function fetchJSON(res, options) {
   -1    27 	var response = await fetch(res, options);
   -1    28 	if (response.ok) {
   -1    29 		return await response.json();
   -1    30 	} else {
   -1    31 		throw response;
   -1    32 	}
   34    33 }
   35    34 
   36    35 var sendChanges = utils.throttled(function() {
@@ -101,7 +100,7 @@ function handleMessage(msg) {
  101   100 	}
  102   101 }
  103   102 
  104    -1 function consolidate() {
   -1   103 async function consolidate() {
  105   104 	var text = el.value;
  106   105 	var myChanges = [].concat(stagedChanges, localChanges);
  107   106 
@@ -110,7 +109,7 @@ function consolidate() {
  110   109 	}
  111   110 
  112   111 	var data = [id, 'changes', [diff.diff('', text, 3)]];
  113    -1 	return fetch(url, {
   -1   112 	await fetch(url, {
  114   113 		method: 'PUT',
  115   114 		body: JSON.stringify(data),
  116   115 		headers: {'Last-Event-ID': lastEventId},
@@ -124,20 +123,18 @@ el.addEventListener('input', () => {
  124   123 	sendChanges();
  125   124 });
  126   125 
  127    -1 document.querySelector('button').addEventListener('click', () => {
   -1   126 document.querySelector('button').addEventListener('click', async () => {
  128   127 	if (!confirm('Are you sure you want to delete all data?')) {
  129   128 		return;
  130   129 	}
  131   130 
  132   131 	var data = [id, 'changes', [diff.diff('', '', 3)]];
  133    -1 	return fetch(url, {
   -1   132 	await fetch(url, {
  134   133 		method: 'POST',
  135   134 		body: JSON.stringify(data),
  136    -1 	}).then(() => {
  137    -1 		return fetch(url, {method: 'DELETE'});
  138    -1 	}).then(() => {
  139    -1 		location.reload();
  140   135 	});
   -1   136 	await fetch(url, {method: 'DELETE'});
   -1   137 	location.reload();
  141   138 });
  142   139 
  143   140 var eventSource = new EventSource(url);