Plugin
LocalMessageEditor
Ermöglicht das lokale Bearbeiten von Nachrichten anderer Nutzer - nur für dich sichtbar!
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen —
%appdata%\\BetterDiscord\\plugins
(Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
localmessageeditor.plugin.js · 404 Zeilen · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
FILE META START
name: localmessageeditor.plugin.js
version: 0.0.10
description: Multi-surface admin, cloud, bot host, login, and secure chat server.
lastModified: 2026-05-04T20:22:59.671Z
checksum: 7f783c5c94d0b002e517faee68aa90f9f9f7725e4c29bcbaf28719c2888f9ae4
FILE META END
*/
/**
* @name LocalMessageEditor
* @author HeadX
* @authorId 808385710700494919
* @description Ermöglicht das lokale Bearbeiten von Nachrichten anderer Nutzer - nur für dich sichtbar!
* @version 2.0.1
* @invite J6wTJJ5fp
* @website https://headcraft.cloud/better-discord
* @source https://headcraft.cloud/better-discord/LocalMessageEditor.plugin.js
* @updateUrl https://headcraft.cloud/better-discord/LocalMessageEditor.plugin.js
*/
module.exports = class LocalMessageEditor {
constructor() {
this.name = "LocalMessageEditor";
this.editedMessages = new Map();
this.contextMenuPatch = null;
}
start() {
this.loadEdits();
this.addStyles();
this.patchContextMenu();
this.applyEdits();
this._autoUpdate();
BdApi.showToast("LocalMessageEditor gestartet!", { type: "success" });
}
stop() {
if (this.contextMenuPatch) this.contextMenuPatch();
BdApi.DOM.removeStyle(this.name);
this.restoreAllMessages();
this.saveEdits();
}
loadEdits() {
try {
const saved = BdApi.Data.load(this.name, "editedMessages") || {};
this.editedMessages = new Map(Object.entries(saved));
console.log("[LocalMessageEditor] Loaded", this.editedMessages.size, "edits");
} catch (e) {
console.error("[LocalMessageEditor] Fehler beim Laden:", e);
this.editedMessages = new Map();
}
}
saveEdits() {
try {
const toSave = Object.fromEntries(this.editedMessages);
BdApi.Data.save(this.name, "editedMessages", toSave);
} catch (e) {
console.error("[LocalMessageEditor] Fehler beim Speichern:", e);
}
}
addStyles() {
const css = `
.lme-edited-indicator {
font-size: 0.625rem;
color: var(--text-muted);
margin-left: 4px;
cursor: help;
}
.lme-modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.85);
display: flex;
align-items: center;
justify-content: center;
z-index: 10000;
}
.lme-modal {
background: var(--background-primary);
border-radius: 8px;
padding: 20px;
width: 500px;
max-width: 90%;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.lme-modal h2 {
color: var(--header-primary);
margin: 0 0 8px 0;
font-size: 20px;
}
.lme-modal-info {
color: var(--text-muted);
margin: 0 0 12px 0;
font-size: 12px;
}
.lme-textarea {
width: 100%;
min-height: 100px;
padding: 10px;
background: var(--channeltextarea-background);
border: none;
border-radius: 4px;
color: var(--text-normal);
font-family: inherit;
font-size: 1rem;
resize: vertical;
outline: none;
box-sizing: border-box;
}
.lme-textarea:focus {
outline: 2px solid var(--brand-experiment);
}
.lme-buttons {
display: flex;
gap: 8px;
margin-top: 12px;
justify-content: flex-end;
}
.lme-btn {
padding: 8px 16px;
border: none;
border-radius: 3px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
}
.lme-btn-primary {
background: var(--brand-experiment);
color: white;
}
.lme-btn-primary:hover {
background: var(--brand-experiment-560);
}
.lme-btn-secondary {
background: var(--button-secondary-background);
color: var(--text-normal);
}
.lme-btn-danger {
background: hsl(359, 82.6%, 59.4%);
color: white;
}
`;
BdApi.DOM.addStyle(this.name, css);
}
patchContextMenu() {
this.contextMenuPatch = BdApi.ContextMenu.patch("message", (tree, props) => {
if (!props?.message) return;
const message = props.message;
const isEdited = this.editedMessages.has(message.id);
// Erstelle Menu Items
const editItem = BdApi.ContextMenu.buildItem({
type: "text",
label: isEdited ? "✏️ Lokale Bearbeitung ändern" : "✏️ Lokal bearbeiten",
action: () => this.openEditModal(message)
});
const items = [editItem];
if (isEdited) {
items.push(BdApi.ContextMenu.buildItem({
type: "text",
label: "🗑️ Lokale Bearbeitung entfernen",
danger: true,
action: () => this.resetEdit(message.id)
}));
}
// Füge Gruppe hinzu
const group = BdApi.ContextMenu.buildItem({
type: "group",
items: items
});
// Füge zum Menü hinzu
tree.props.children.push(group);
});
}
openEditModal(message) {
const currentContent = this.editedMessages.get(message.id) || message.content;
// Erstelle Modal
const overlay = document.createElement('div');
overlay.className = 'lme-modal-overlay';
overlay.innerHTML = `
<div class="lme-modal">
<h2>Nachricht lokal bearbeiten</h2>
<p class="lme-modal-info">Von: ${this.escapeHtml(message.author?.username || 'Unbekannt')} • Nur für dich sichtbar!</p>
<textarea class="lme-textarea">${this.escapeHtml(currentContent)}</textarea>
<div class="lme-buttons">
<button class="lme-btn lme-btn-secondary" id="lme-cancel">Abbrechen</button>
${this.editedMessages.has(message.id) ? '<button class="lme-btn lme-btn-danger" id="lme-reset">Zurücksetzen</button>' : ''}
<button class="lme-btn lme-btn-primary" id="lme-save">Speichern</button>
</div>
</div>
`;
document.body.appendChild(overlay);
const textarea = overlay.querySelector('textarea');
textarea.focus();
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
// Event Handlers
const close = () => overlay.remove();
overlay.addEventListener('click', (e) => {
if (e.target === overlay) close();
});
overlay.querySelector('#lme-cancel').onclick = close;
overlay.querySelector('#lme-save').onclick = () => {
const newContent = textarea.value.trim();
if (newContent && newContent !== message.content) {
this.editedMessages.set(message.id, newContent);
this.saveEdits();
this.applyEditToMessage(message.id, newContent);
BdApi.showToast("Nachricht lokal bearbeitet!", { type: "success" });
}
close();
};
const resetBtn = overlay.querySelector('#lme-reset');
if (resetBtn) {
resetBtn.onclick = () => {
this.resetEdit(message.id);
close();
};
}
// ESC to close
const escHandler = (e) => {
if (e.key === 'Escape') {
close();
document.removeEventListener('keydown', escHandler);
}
};
document.addEventListener('keydown', escHandler);
}
applyEdits() {
// Warte kurz und wende dann alle Edits an
setTimeout(() => {
for (const [messageId, content] of this.editedMessages) {
this.applyEditToMessage(messageId, content);
}
}, 1000);
// Beobachte DOM für neue Nachrichten
this.setupObserver();
}
setupObserver() {
const observer = new MutationObserver(() => {
for (const [messageId, content] of this.editedMessages) {
this.applyEditToMessage(messageId, content);
}
});
const chatArea = document.querySelector('[class*="chatContent"]');
if (chatArea) {
observer.observe(chatArea, { childList: true, subtree: true });
}
this.observer = observer;
}
applyEditToMessage(messageId, newContent) {
// Finde Message Content Element
const messageEl = document.querySelector(`[id="message-content-${messageId}"]`);
if (!messageEl) return;
// Speichere Original wenn noch nicht gespeichert
if (!messageEl.dataset.lmeOriginal) {
messageEl.dataset.lmeOriginal = messageEl.textContent;
}
// Prüfe ob bereits bearbeitet
if (messageEl.dataset.lmeEdited === "true") return;
// Ersetze Inhalt
messageEl.textContent = newContent;
messageEl.dataset.lmeEdited = "true";
// Füge Indikator hinzu
const indicator = document.createElement('span');
indicator.className = 'lme-edited-indicator';
indicator.textContent = ' (lokal bearbeitet)';
indicator.title = 'Original: ' + messageEl.dataset.lmeOriginal;
messageEl.appendChild(indicator);
}
resetEdit(messageId) {
this.editedMessages.delete(messageId);
this.saveEdits();
// Stelle Original wieder her
const messageEl = document.querySelector(`[id="message-content-${messageId}"]`);
if (messageEl && messageEl.dataset.lmeOriginal) {
messageEl.textContent = messageEl.dataset.lmeOriginal;
delete messageEl.dataset.lmeEdited;
delete messageEl.dataset.lmeOriginal;
}
BdApi.showToast("Bearbeitung entfernt!", { type: "info" });
}
restoreAllMessages() {
const editedEls = document.querySelectorAll('[data-lme-edited="true"]');
editedEls.forEach(el => {
if (el.dataset.lmeOriginal) {
el.textContent = el.dataset.lmeOriginal;
}
delete el.dataset.lmeEdited;
delete el.dataset.lmeOriginal;
});
if (this.observer) {
this.observer.disconnect();
}
}
escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
getSettingsPanel() {
const panel = document.createElement('div');
panel.style.padding = '16px';
panel.style.color = 'var(--text-normal)';
panel.innerHTML = `
<h2 style="margin: 0 0 16px 0; color: var(--header-primary);">LocalMessageEditor</h2>
<p><strong>Gespeicherte Bearbeitungen:</strong> ${this.editedMessages.size}</p>
<br>
<p><strong>Anleitung:</strong></p>
<ol style="margin: 8px 0 16px 20px; line-height: 1.8;">
<li>Rechtsklick auf eine Nachricht</li>
<li>Klicke auf "✏️ Lokal bearbeiten"</li>
<li>Text ändern und speichern</li>
</ol>
<p style="color: var(--text-muted);">Die Bearbeitung ist nur für dich sichtbar!</p>
`;
const clearBtn = document.createElement('button');
clearBtn.textContent = 'Alle Bearbeitungen löschen';
clearBtn.className = 'lme-btn lme-btn-danger';
clearBtn.style.marginTop = '16px';
clearBtn.onclick = () => {
if (confirm('Alle lokalen Bearbeitungen wirklich löschen?')) {
this.restoreAllMessages();
this.editedMessages.clear();
this.saveEdits();
BdApi.showToast('Alle Bearbeitungen gelöscht!', { type: 'success' });
}
};
panel.appendChild(clearBtn);
return panel;
}
// ===== HeadX Auto-Update System =====
async _autoUpdate() {
const pluginName = this.name || "LocalMessageEditor";
const currentVersion = this.version || this.meta?.version || "0.0.0";
const updateUrl = this.updateUrl || this.meta?.updateUrl || `https://headcraft.cloud/better-discord/${pluginName}.plugin.js`;
try {
const fs = require("fs"), path = require("path");
let res; try { res = await fetch(updateUrl); } catch(e) {}
if (!res?.ok) { try { res = await BdApi.Net.fetch(updateUrl); } catch(e) {} }
if (!res?.ok) return;
const remoteCode = await res.text();
const remoteVersion = remoteCode.match(/@version\s+([^\n\r]+)/)?.[1]?.trim();
if (!remoteVersion) return;
const compare = (a, b) => { const pa = a.split('.').map(Number), pb = b.split('.').map(Number); for (let i = 0; i < Math.max(pa.length, pb.length); i++) { if ((pa[i]||0) > (pb[i]||0)) return 1; if ((pa[i]||0) < (pb[i]||0)) return -1; } return 0; };
if (compare(remoteVersion, currentVersion) <= 0) return;
console.log(`[${pluginName}] Update verfügbar: ${currentVersion} → ${remoteVersion}`);
const pluginsFolder = BdApi.Plugins.folder;
const allFiles = fs.readdirSync(pluginsFolder);
const pluginFile = allFiles.find(f => f.endsWith('.plugin.js') && fs.readFileSync(path.join(pluginsFolder, f), 'utf8').match(new RegExp(`@name\\s+${pluginName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s`))) || `${pluginName}.plugin.js`;
const filePath = path.join(pluginsFolder, pluginFile);
if (typeof BdApi.UI?.showNotification === 'function') {
BdApi.UI.showNotification({ title: `${pluginName} Update`, content: `Version ${remoteVersion} ist verfügbar! (Aktuell: ${currentVersion})`, actions: [{ label: "Jetzt updaten", onClick: () => { fs.writeFileSync(filePath, remoteCode, 'utf8'); BdApi.showToast(`${pluginName} auf v${remoteVersion} aktualisiert!`, { type: "success" }); } }] });
} else { BdApi.showToast(`${pluginName}: Update v${remoteVersion} verfügbar!`, { type: "warning" }); }
} catch (err) { console.error(`[${pluginName}] Auto-Update Fehler:`, err); }
}
// ===== Ende HeadX Auto-Update System =====
};