Plugin
Timezones
Allows you to display other Users' local times.
Installation: Datei herunterladen und in deinen BetterDiscord-Ordner legen —
%appdata%\\BetterDiscord\\plugins
(Windows) bzw. über Discord: Einstellungen → Plugins → Plugin-Ordner öffnen.
Timezones.plugin.js · 420 Zeilen · 15.6 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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
FILE META START
name: Timezones.plugin.js
version: 0.0.10
description: Multi-surface admin, cloud, bot host, login, and secure chat server.
lastModified: 2026-05-04T20:22:59.660Z
checksum: 559606e31ea754a24fa2f9878fb2695530dc82c115cda12d942cbd0168a9e439
FILE META END
*/
/**
* @name Timezones
* @author HeadX
* @authorId 808385710700494919
* @description Allows you to display other Users' local times.
* @version 1.4.4
* @invite J6wTJJ5fp
* @website https://headcraft.cloud/better-discord
* @source https://headcraft.cloud/better-discord/Timezones.plugin.js
* @updateUrl https://headcraft.cloud/better-discord/Timezones.plugin.js
*/
const { Data, React, DOM, Webpack, ContextMenu, UI, Components, Patcher } = new BdApi('Timezones');
const baseConfig = {
info: {
name: "Timezones",
authors: [
{
name: "HeadX",
discord_id: "808385710700494919",
},
],
version: "1.4.3",
description: "Allows you to display other Users' local times.",
},
defaultConfig: [
{
type: "switch",
id: "twentyFourHours",
name: "24 Hour Time",
value: false,
},
{
type: "switch",
id: "showInMessage",
name: "Show local timestamp next to message",
value: true,
},
{
type: "switch",
id: "showOffset",
name: "Show localized GMT format (e.g., GMT-8)",
value: false,
},
],
};
const DataStore = new Proxy(
{},
{
get: (_, key) => {
if (key === 'settings') {
const savedSettings = Data.load(key) || {};
return baseConfig.defaultConfig.reduce((acc, setting) => {
acc[setting.id] = savedSettings[setting.id] ?? setting.value;
return acc;
}, {});
}
return Data.load(key);
},
set: (_, key, value) => {
Data.save(key, value);
return true;
},
deleteProperty: (_, key) => {
Data.delete(key);
return true;
},
}
);
function loadDefaults()
{
if (!Data.load('settings')) {
DataStore.settings = baseConfig.defaultConfig.reduce((acc, setting) => {
acc[setting.id] = setting.value;
return acc;
}, {});
}
}
const config = {
...baseConfig,
defaultConfig: baseConfig.defaultConfig.map(setting => ({
...setting,
value: DataStore.settings[setting.id]
}))
};
const Styles = `
.timezone {
margin-left: 0.5rem;
font-size: 0.75rem;
line-height: 1.375rem;
color: var(--text-muted);
vertical-align: baseline;
display: inline-block;
height: 1.25rem;
cursor: default;
font-weight: 500;
}
[class*="compact"] .timezone {
display: inline;
}
.timezone-margin-top {
margin-top: 0.5rem;
}
.timezone-banner-container {
position: relative;
}
.timezone-badge {
position: absolute;
top: 10px;
left: 10px;
background: var(--profile-body-background-color, var(--background-primary));
border-radius: 4px;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
color: var(--text-normal);
}
`;
let Markdown, SearchableSelect, ProfileBanner, MessageHeader, Tooltip, i18n;
let ProfileBannerKey, MessageHeaderKey;
function findExportKey(mod, filter) {
if (!mod) return null;
for (const key of Object.keys(mod)) {
try {
if (typeof mod[key] === 'function' && filter(mod[key])) return key;
} catch(e) {}
}
return null;
}
function initModules() {
try {
Markdown = Webpack.getModule((m) => m?.rules && m?.defaultProps?.parser) ||
Webpack.getModule((m) => m?.rules && m?.parse);
SearchableSelect = Webpack.getModule(m => m?.render?.toString?.()?.includes('focusFirstVisibleItem'), { searchExports: true }) ||
Webpack.getModule(m => m?.toString?.()?.includes('SearchableSelect'), { searchExports: true }) ||
Webpack.getModule(m => m?.toString?.()?.includes('searchableSelect'), { searchExports: true });
ProfileBanner = Webpack.getModule(m => m?.toString?.()?.includes('canUsePremiumProfileCustomization'), { defaultExport: false }) ||
Webpack.getModule(m => m?.toString?.()?.includes('profileBanner'), { defaultExport: false });
MessageHeader = Webpack.getModule(m => m?.toString?.()?.includes('userOverride'), { defaultExport: false }) ||
Webpack.getModule(m => m?.toString?.()?.includes('messageHeader'), { defaultExport: false });
Tooltip = Components?.Tooltip || Webpack.getModule(m => m?.displayName === 'Tooltip');
i18n = Webpack.getByKeys("getLocale") || { getLocale: () => "de-DE" };
// Dynamically find the export keys instead of hardcoding .Z
if (ProfileBanner) {
ProfileBannerKey = findExportKey(ProfileBanner, fn => fn.toString?.()?.includes('canUsePremiumProfileCustomization') || fn.toString?.()?.includes('profileBanner'));
if (!ProfileBannerKey) ProfileBannerKey = ProfileBanner.Z ? 'Z' : ProfileBanner.ZP ? 'ZP' : ProfileBanner.default ? 'default' : null;
}
if (MessageHeader) {
MessageHeaderKey = findExportKey(MessageHeader, fn => fn.toString?.()?.includes('userOverride') || fn.toString?.()?.includes('messageHeader'));
if (!MessageHeaderKey) MessageHeaderKey = MessageHeader.Z ? 'Z' : MessageHeader.ZP ? 'ZP' : MessageHeader.default ? 'default' : null;
}
console.log("[Timezones] Modules loaded. ProfileBannerKey:", ProfileBannerKey, "MessageHeaderKey:", MessageHeaderKey);
} catch (e) {
console.error("[Timezones] Module init error:", e);
}
}
const TimezonesPanel = () => {
const [settings, setSettings] = React.useState({ ...DataStore.settings });
const handleSettingChange = (id, value) => {
setSettings(prevSettings => {
const newSettings = {
...prevSettings,
[id]: value
};
DataStore.settings = newSettings;
return newSettings;
});
};
return UI.buildSettingsPanel({
settings: config.defaultConfig.map(setting => ({
...setting,
value: settings[setting.id]
})),
onChange: (_, id, value) => handleSettingChange(id, value)
});
};
class Timezones {
constructor()
{
loadDefaults();
}
start() {
initModules();
DOM.addStyle("Timezones-Styles", Styles);
try {
ContextMenu.patch("user-context", this.userContextPatch);
} catch (e) {
console.error("[Timezones] ContextMenu patch error:", e);
}
try {
if (ProfileBanner && ProfileBannerKey) {
Patcher.after(ProfileBanner, ProfileBannerKey, (_, [props], ret) => {
if (!props?.user?.id || !this.hasTimezone(props.user.id)) return;
if (!ret?.props) return;
ret.props.children = React.createElement(Tooltip || 'div', {
text: this.getTime(props.user.id, Date.now(), { weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "numeric", minute: "numeric" }) +
` (${DataStore[props.user.id]})`,
children: (p) => React.createElement("div", { ...p, className: "timezone-badge" }, this.getTime(props.user.id, Date.now(), { hour: "numeric", minute: "numeric" })),
});
});
}
} catch (e) {
console.error("[Timezones] ProfileBanner patch error:", e);
}
try {
if (MessageHeader && MessageHeaderKey) {
Patcher.after(MessageHeader, MessageHeaderKey, (_, [props], ret) => {
if (!props?.message?.author?.id) return;
if (props.isRepliedMessage || !DataStore.settings.showInMessage) return;
if (!this.hasTimezone(props.message.author.id)) return;
if (!ret?.props?.children) return;
ret.props.children.push(
React.createElement(Tooltip || 'span', {
text: this.getTime(props.message.author.id, props.message.timestamp, {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
}) + ` (${DataStore[props.message.author.id]})`,
children: (p) =>
React.createElement(
"span",
{ ...p, className: "timezone" },
this.getTime(props.message.author.id, props.message.timestamp, { hour: "numeric", minute: "numeric" })
),
})
);
});
}
} catch (e) {
console.error("[Timezones] MessageHeader patch error:", e);
}
this._autoUpdate();
BdApi.showToast("Timezones aktiviert!", { type: "success" });
}
userContextPatch = (ret, props) => {
const isDM = !Array.isArray(ret.props.children[0].props.children);
(isDM ? ret.props.children : ret.props.children[0].props.children).push([
ContextMenu.buildItem({ type: "separator" }),
ContextMenu.buildItem({
type: "submenu",
label: "Timezones",
children: [
DataStore[props.user.id] &&
ContextMenu.buildItem({
type: "text",
disabled: true,
label: DataStore[props.user.id],
}),
ContextMenu.buildItem({
label: DataStore[props.user.id] ? "Change Timezone" : "Set Timezone",
action: () => {
return this.setTimezone(props.user.id, props.user);
},
}),
ContextMenu.buildItem({
label: "Remove Timezone",
danger: true,
disabled: !this.hasTimezone(props.user.id),
action: () => {
return this.removeTimezone(props.user.id, props.user);
},
}),
].filter((x) => x),
}),
]);
};
hasTimezone(id) {
const value = DataStore[id];
return !Array.isArray(value) && !!value;
}
setTimezone(id, user) {
let outvalue = null;
const options = Intl.supportedValuesOf("timeZone").map((timezone) => {
const offset = new Intl.DateTimeFormat(undefined, { timeZone: timezone, timeZoneName: "short" })
.formatToParts(new Date())
.find((part) => part.type === "timeZoneName").value;
return { label: `${timezone} (${offset})`, value: timezone };
});
UI.showConfirmationModal(
`Set Timezone for ${user.username}`,
[
React.createElement(Markdown, null, "Please select a timezone."),
React.createElement(() => {
const [currentValue, setCurrentValue] = React.useState(DataStore[id] || null);
return React.createElement(SearchableSelect, {
options,
value: options.find((o) => o.value === currentValue),
placeholder: "Select a Timezone",
maxVisibleItems: 5,
closeOnSelect: true,
onChange: (value) => {
setCurrentValue(value);
outvalue = value;
},
});
}),
],
{
confirmText: "Set",
onConfirm: () => {
DataStore[id] = outvalue;
UI.showToast(`Timezone set to ${outvalue} for ${user.username}`, {
type: "success",
});
},
}
);
}
removeTimezone(id, user) {
delete DataStore[id];
UI.showToast(`Timezone removed for ${user.username}`, {
type: "success",
});
}
getTime(id, time, props) {
const timezone = DataStore[id];
if (!timezone) return null;
const date = new Date(time);
const formatter = new Intl.DateTimeFormat(i18n?.getLocale?.() ?? "en-US", {
hourCycle: DataStore.settings.twentyFourHours ? "h23" : "h12",
timeZone: timezone,
timeZoneName: DataStore.settings.showOffset ? "shortOffset" : undefined,
...props,
});
return formatter.format(date);
}
// ===== HeadX Auto-Update System =====
async _autoUpdate() {
const pluginName = "Timezones";
const currentVersion = "1.4.4";
const 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 =====
stop() {
Patcher.unpatchAll();
ContextMenu.unpatch("user-context", this.userContextPatch);
DOM.removeStyle("Timezones-Styles");
}
getSettingsPanel() {
return React.createElement(TimezonesPanel);
}
}
module.exports = Timezones;