- commit
- 72da842c5087266566ea6819f785fca68cac8909
- parent
- 6f6aea8696c1a7dccaec000b3da9ed4dd45737c9
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-06-06 12:01
lint
Diffstat
M | static/pad.js | 18 | +++++++----------- |
1 files changed, 7 insertions, 11 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -41,7 +41,7 @@ var sendChanges = utils.throttled(function() { 41 41 } else { 42 42 throw response; 43 43 }44 -1 }).catch(err => {-1 44 }).catch(() => { 45 45 if (failedRequests > 3) { 46 46 exit(); 47 47 } else { @@ -55,21 +55,19 @@ var sendChanges = utils.throttled(function() { 55 55 }, 500); 56 56 57 57 var applyChanges = function(changes) {58 -1 var change;59 -160 58 var selection = [el.selectionStart, el.selectionEnd, el.selectionDirection]; 61 59 var text = el.value; 62 60 var myChanges = [].concat(stagedChanges, localChanges); 63 6164 -1 for (change of myChanges.slice().reverse()) {-1 62 for (const change of myChanges.slice().reverse()) { 65 63 text = diff.unapply(text, change, selection); 66 64 } 67 6568 -1 for (change of changes) {-1 66 for (const change of changes) { 69 67 text = diff.apply(text, change, selection); 70 68 } 71 6972 -1 for (change of myChanges) {-1 70 for (const change of myChanges) { 73 71 text = diff.apply(text, change, selection); 74 72 } 75 73 @@ -97,16 +95,14 @@ var handleMessage = function(msg) { 97 95 }; 98 96 99 97 var consolidate = function(lastEventId) {100 -1 var change;101 98 var text = el.value; 102 99 var myChanges = [].concat(stagedChanges, localChanges); 103 100104 -1 for (change of myChanges.slice().reverse()) {-1 101 for (const change of myChanges.slice().reverse()) { 105 102 text = diff.unapply(text, change); 106 103 } 107 104108 -1 change = diff.diff('', text, 3);109 -1 var data = [id, 'changes', [change]];-1 105 var data = [id, 'changes', [diff.diff('', text, 3)]]; 110 106 fetch(url, { 111 107 method: 'PUT', 112 108 body: JSON.stringify(data), @@ -143,7 +139,7 @@ eventSource.onmessage = function(event) { 143 139 144 140 window.addEventListener('offline', exit); 145 141146 -1 window.addEventListener('beforeunload', event => {-1 142 window.addEventListener('beforeunload', () => { 147 143 if (localChanges.length) { 148 144 var data = [id, 'changes', localChanges]; 149 145 navigator.sendBeacon(url, JSON.stringify(data));