-
Notifications
You must be signed in to change notification settings - Fork 6
/
timer-selector.js
733 lines (657 loc) · 28.3 KB
/
timer-selector.js
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
// Constants
var SECONDS_MS = 1000;
var MINUTES_MS = SECONDS_MS * 60;
var HOURS_MS = MINUTES_MS * 60;
var DAYS_MS = HOURS_MS * 24;
// Initialization errors are only in English unfortunately.
function setError(primary, secondary = null) {
var errorElement = document.getElementById('error');
errorElement.classList.remove('hidden');
errorElement.innerText = primary;
var formElement = document.getElementById('form');
formElement.classList.add('hidden');
if (secondary) {
var secondaryErrorElement = document.createElement('div');
secondaryErrorElement.classList = ['error-secondary'];
secondaryErrorElement.innerText = secondary;
errorElement.appendChild(secondaryErrorElement);
}
}
// Localization
var TRANSLATIONS = {
// Test _mostly_ returns the message key but there are a few special cases
'test': {
'template-deletion': 'score: %%score%%\n\nsummary:%%summary%%\n\niframe: %%iframe%%',
'summary-deletion-reason-skeleton': '**(%%reason%%).**',
'summary-deletion-reasons': ['1', '2', '3'],
},
// English
'en': {
'timer-description': 'Timer expiring at',
'timer-progress': 'This timer will expire in',
'timer-finished': 'This timer has been expired since',
'timer-type': 'Timer Type',
'timer-type-generic': 'Generic',
'timer-type-deletion': 'Deletion',
'timer-type-ban': 'Ban',
'deletion-options': 'Deletion Options',
'deletion-score': 'Article\'s current score',
'summary-deletion': 'Reason for summary deletion (optional)',
'summary-deletion-reason-none': 'N/A',
'summary-deletion-reason-skeleton': '**Also witnessing for summary deletion (%%reason%%).**',
'summary-deletion-reasons': [
'use of generative AI',
'plagiarism',
'vote manipulation',
'trolling',
'out of range',
'blank/unfinished',
'\'gaming\' site procedure',
'malicious content/physically harmful',
],
'duration': 'Duration',
'duration-1d': '1 Day',
'duration-1w': '1 Week',
'duration-2w': '2 Weeks',
'duration-1y': '1 Year',
'duration-custom': 'Custom',
'unit-minute': 'minutes',
'unit-hour': 'hours',
'unit-day': 'days',
'unit-week': 'weeks',
'unit-month': 'months',
'unit-year': 'years',
'start-time': 'Start Time',
'start-time-now': 'Now',
'start-time-later': 'Later',
'messages': 'Messages',
'message-progress': 'Timer in-progress (optional)',
'message-finished': 'Timer finished (optional)',
'advanced-section': 'Advanced',
'height': 'Height',
'width': 'Width',
'css-extra': 'Custom timer CSS (optional)',
'template': 'Output template',
'template-deletion': 'Beginning deletion confirmation at %%score%%.%%summary%%\n\n%%iframe%%\n\nIf this article is over a year old, you are not the author, and you want to rewrite this article, PM a member of the [[[rewrite-guide|Rewrite Team]]]. Please request permission from the author and make sure you copy the page source to your sandbox. **Do not reply to this post unless you are staff.**',
'template-ban': '%%iframe%%',
'message-deletion-progress': 'This page will be eligible for deletion in',
'message-deletion-finished': 'This page has been eligible for deletion since',
'message-ban-progress': 'This user\'s ban will elapse in',
'message-ban-finished': 'This user\'s ban has been expired since',
'build-timer': 'Build timer',
'build-and-copy-timer': 'Build timer and copy to clipboard',
'info-help': 'help',
'info-source': 'source',
'error-missing': 'Please make a selection in each section first.',
'error-invalid': 'Invalid internal state, please file a bug report.',
},
// French
'fr': {
'timer-description': 'Fin du compte à rebours à',
'timer-progress': 'Ce compte à rebours se terminera dans',
'timer-finished': 'Ce compte à rebous est terminé depuis',
'timer-type': 'Type de compte à rebours',
'timer-type-generic': 'Générique',
'timer-type-deletion': 'Suppression',
'timer-type-ban': 'Bannissement',
'deletion-options': 'Options de suppression',
'deletion-score': 'Note actuelle de l\'article',
'summary-deletion-reasons': [],
'duration': 'Durée',
'duration-1d': '1 jour',
'duration-1w': '1 semaine',
'duration-2w': '2 semaines',
'duration-1y': '1 an',
'duration-custom': 'Personnalisé',
'unit-minute': 'minutes',
'unit-hour': 'heures',
'unit-day': 'jours',
'unit-week': 'semaines',
'unit-month': 'mois',
'unit-year': 'ans',
'start-time': 'Heure de départ',
'start-time-now': 'Maintenant',
'start-time-later': 'Plus tard',
'messages': 'Messages',
'message-progress': 'Compte à rebours en cours (optionnel)',
'message-finished': 'Compte à rebours terminé (optionnel)',
'advanced-section': 'Avancé',
'height': 'Hauteur',
'width': 'Largeur',
'css-extra': 'CSS personnalisé pour le compte à rebours (optionnel)',
'template': "Modèle d'output",
'template-deletion': "Début du compte à rebours de suppression à %%score%%.\n\n%%iframe%%\n\nCe message est ouvert aux réponses de l'auteur ou d'un autre membre désirant éventuellement réécrire l'article, avec l'autorisation de l'auteur s'il est encore actif.",
'template-ban': '%%iframe%%',
'message-deletion-progress': 'Cette page pourra être supprimée dans',
'message-deletion-finished': 'Cette page peut être supprimée depuis',
'message-ban-progress': "Le bannissement de l'utilisateur se terminera dans",
'message-ban-finished': "Le bannissement de l'utilisateur est terminé depuis",
'build-timer': 'Définir un compte à rebours',
'build-and-copy-timer': 'Build timer and copy to clipboard NEEDS TRNASLATION',
'info-help': 'aide',
'info-source': 'source',
'error-missing': 'Veuillez sélectionner une option dans chaque section avant.',
'error-invalid': 'État interne invalide, veuillez signaler ce problème.',
},
// Pig Latin
'pig': {
'timer-description': 'Imertay expiringyay atyay',
'timer-progress': 'Isthay imertay illway expireyay inyay',
'timer-finished': 'Isthay imertay ashay eenbay expiredyay incesay',
'timer-type': 'Imertay Ypetay',
'timer-type-generic': 'Enericgay',
'timer-type-deletion': 'Eletionday',
'timer-type-ban': 'Anbay',
'deletion-options': 'Eletionday Optionsyay',
'deletion-score': 'article\'syay urrentcay orescay',
'summary-deletion-reasons': [],
'duration': 'Urationday',
'duration-1d': '1 Aday',
'duration-1w': '1 Eekway',
'duration-2w': '2 Eeksway',
'duration-1y': '1 Earyay',
'duration-custom': 'Ustomcay',
'unit-minute': 'inutesmay',
'unit-hour': 'ourshay',
'unit-day': 'aysday',
'unit-week': 'eeksway',
'unit-month': 'onthsmay',
'unit-year': 'earsyay',
'start-time': 'Artstay Imetay',
'start-time-now': 'Ownay',
'start-time-later': 'Aterlay',
'messages': 'Essagesmay',
'message-progress': 'Imertay in-progressyay (optionalyay)',
'message-finished': 'Imertay inishedfay (optionalyay)',
'advanced-section': 'Advancedyay',
'height': 'Eighthay',
'width': 'Idthway',
'css-extra': 'Ustomcay imertay CSSYAY (optionalyay)',
'template': 'Outputyay emplatetay',
'template-deletion': 'Eginningbay eletionday otevay atyay %%score%%.\n\n%%iframe%%\n\nIfyay isthay articleyay isyay overyay ayay earyay oldyay, ouyay areyay otnay ethay authoryay, andyay ouyay antway otay ewriteray isthay articleyay, equestray otay oday osay inyay ethay [/forum/t-14018096/rewrite-request-thread#post-4916192 Ewriteray Equestray Eadthray]. Easeplay equestray ermissionpay omfray ehtay authoryay andyay akemay uresay ouyay opycay ehtay agepay ourcesay otay ouryay andboxsay. **Oday otnay eplyray otay isthay ostay unlessyay ouyay areyay affstay.**',
'template-ban': '%%iframe%%',
'message-deletion-progress': 'Isthay agepay illway ebay eligibleyay orfay eletionday inyay',
'message-deletion-finished': 'Isthay agepay has been eligible for deletion since',
'message-ban-progress': 'Isthay user\'syay anbay illway elapseyay inyay',
'message-ban-finished': 'Isthay user\'syay anbay ashay eenbay expiredyay incesay',
'build-timer': 'Uildbay imertay',
'build-and-copy-timer': 'Uildbay imertay andyay opycay otay ipboardclay',
'info-help': 'elphay',
'info-source': 'ourcesay',
'error-missing': 'Easeplay akemay ayay electionsay inyay eachyay ectionsay irstfay.',
'error-invalid': 'Invalidyay internalyay atestay, easeplay ilefay ayay ugbay eportray.',
},
// Spanish
'es': {
'timer-description': 'El temporizador finaliza en',
'timer-progress': 'El temporizador finalizará en',
'timer-finished': 'El temporizador ha finalizado desde hace',
'timer-type': 'Tipo de Temporizador',
'timer-type-generic': 'Genérico',
'timer-type-deletion': 'Eliminación',
'timer-type-ban': 'Ban',
'deletion-options': 'Deletion Options NEEDS TRANSLATION', // TODO
'deletion-score': 'Article\'s current score NEEDS TRANSLATION', // TODO
'summary-deletion-reasons': [],
'duration': 'Duración',
'duration-1d': '1 Día',
'duration-1w': '1 Semana',
'duration-2w': '2 Semanas',
'duration-1y': '1 Año',
'duration-custom': 'Personalizado',
'unit-minute': 'minutos',
'unit-hour': 'horas',
'unit-day': 'días',
'unit-week': 'semanas',
'unit-month': 'meses',
'unit-year': 'años',
'start-time': 'Hora de Inicio',
'start-time-now': 'Ahora',
'start-time-later': 'Luego',
'messages': 'Mensajes',
'message-progress': 'Temporizador en progreso (opcional)',
'message-finished': 'Temporizador finalizado (opcional)',
'advanced-section': 'Avanzado',
'height': 'Alto',
'width': 'Ancho',
'css-extra': 'CSS personalizado del temporizador (opcional)',
'template': 'Modelo de salida',
'template-deletion': 'Comienzo de la eliminación en %%score%%.\n\n%%iframe%%\n\nSi no eres el autor y desea reescribir este artículo, puede responder a este post solicitando la oportunidad de hacerlo. Obtenga permiso del autor (o de la administración si este artículo tiene más de 6 meses) y asegúrese de copiar el código fuente del artículo en su borrador. **Por favor, __no__ responda a este post por cualquier otra razón a menos que seas parte del Staff.**',
'template-ban': '%%iframe%%',
'message-deletion-progress': 'Esta página podrá ser eliminada en',
'message-deletion-finished': 'Esta página puede ser eliminada desde',
'message-ban-progress': 'El ban de este usuario finalizará en',
'message-ban-finished': 'El ban del usuario ha finalizado desde',
'build-timer': 'Crear temporizador',
'build-and-copy-timer': 'Build timer and copy to clipboard NEEDS TRNASLATION',
'info-help': 'ayuda',
'info-source': 'código fuente',
'error-missing': 'Por favor, haga una selección en cada sección primero.',
'error-invalid': 'Estado interno inválido, por favor, presente un informe de error.',
},
// Vietnamese
'vi': {
'timer-description': 'Đồng hồ kết thúc vào',
'timer-progress': 'Đồng hồ sẽ kết thúc trong',
'timer-finished': 'Đồng hồ này đã kết thúc kể từ',
'timer-type': 'Loại Đồng Hồ',
'timer-type-generic': 'Chung',
'timer-type-deletion': 'Xóa Bài',
'timer-type-ban': 'Chặn Người Dùng',
'deletion-options': 'Deletion Options NEEDS TRANSLATION', // TODO
'deletion-score': 'Article\'s current score NEEDS TRANSLATION', // TODO
'summary-deletion-reasons': [],
'duration': 'Thời Gian',
'duration-1d': '1 Ngày',
'duration-1w': '1 Tuần',
'duration-2w': '2 Tuần',
'duration-1y': '1 Năm',
'duration-custom': 'Khác',
'unit-minute': 'phút',
'unit-hour': 'giờ',
'unit-day': 'ngày',
'unit-week': 'tuần',
'unit-month': 'tháng',
'unit-year': 'năm',
'start-time': 'Đồng Hồ Bắt Đầu Vào',
'start-time-now': 'Bây giờ',
'start-time-later': 'Bắt đầu sau',
'messages': 'Chữ hiện trên đồng hồ',
'message-progress': 'Chữ hiện khi đồng hồ chưa kết thúc (không bắt buộc)',
'message-finished': 'Chữ hiện khi đồng hồ đã kết thúc (không bắt buộc)',
'advanced-section': 'Cài Đặt Nâng Cao',
'height': 'Chiều cao',
'width': 'Chiều rộng',
'css-extra': 'CSS tùy chỉnh (không bắt buộc)',
'template': 'Mẫu code',
'template-deletion': '[[=]]\n\n**Bài sẽ bị xóa khi đồng hồ dưới đây đếm ngược về %%score%%:**\n\n%%iframe%%\n\n[[/=]]\n\n**Lý do xóa:** Rating bài dưới -5.\n\n**Nếu bạn không phải là tác giả và muốn viết lại bài viết này, hãy trả lời bình luận này, liên hệ với tác giả và lưu lại mã nguồn. Ngoài ra, làm ơn không trả lời bình luận này trừ khi bạn là nhân viên.**',
'template-ban': '%%iframe%%',
'message-deletion-progress': 'Trang này sẽ đủ điều kiện xóa trong',
'message-deletion-finished': 'Trang này đã đủ điều kiện xóa từ',
'message-ban-progress': 'Lệnh chặn người dùng này sẽ hết hạn vào',
'message-ban-finished': 'Lệnh chặn người dùng này đã hết hạn từ',
'build-timer': 'Tạo đồng hồ',
'build-and-copy-timer': 'Build timer and copy to clipboard NEEDS TRNASLATION',
'info-help': 'trợ giúp',
'info-source': 'mã nguồn',
'error-missing': 'Hãy chọn đầy đủ các tùy chọn bắt buộc',
'error-invalid': 'Lỗi phần mềm, vui lòng gửi báo cáo lỗi.',
},
// Simplified Chinese
'cn': {
'timer-description': '此计时器将过期于:',
'timer-progress': '此计时器将过期于:',
'timer-finished': '此计时器已过期:',
'timer-type': '计时器类型',
'timer-type-generic': '通用',
'timer-type-deletion': '删除',
'timer-type-ban': '封禁',
'deletion-options': '删除选项',
'deletion-score': '当前文章的分数为',
'summary-deletion-reasons': [],
'duration': '运行时间',
'duration-1d': '1日',
'duration-1w': '1周',
'duration-2w': '2周',
'duration-1y': '1年',
'duration-custom': '自定义',
'unit-minute': '分钟',
'unit-hour': '小时',
'unit-day': '日',
'unit-week': '周',
'unit-month': '月',
'unit-year': '年',
'start-time': '开始时间',
'start-time-now': '现在',
'start-time-later': '稍后',
'messages': '通知内容',
'message-progress': '此计时器运行中(可选)',
'message-finished': '此计时器已到期(可选)',
'advanced-section': '高级设置',
'height': '高度',
'width': '宽度',
'css-extra': '自定计时器样式(可选)',
'template': '输出模板',
'template-deletion': '由于条目的分数为%%score%%分,现根据[[[deletions-guide|删帖指导]]],宣告将删除此页:\n\n%%iframe%%\n\n**如果你不是作者又想要重写该条目,请在此帖回复申请。请先取得作者(或管理员,如果此文档搬运自聊天室的话)的同意,并将原文的源代码复制至沙盒里。除非你是工作人员,否则请勿就申请重写以外的范围回复此帖。**',
'template-ban': '%%iframe%%',
'message-deletion-progress': '此页面将在计时器到期后可供删除:',
'message-deletion-finished': '此页面在下列时间前已可供删除:',
'message-ban-progress': '此用户的封禁将到期于:',
'message-ban-finished': '此用户的封禁已到期:',
'build-timer': '生成计时器',
'build-and-copy-timer': '生成并复制',
'info-help': '帮助',
'info-source': '来源',
'error-missing': '请先在每个项中做选择。',
'error-invalid': '内部状态无效,请提交错误报告。',
},
};
function getMessage(language, messageKey, optionalMessage = false) {
// Get message based on language
var messages = TRANSLATIONS[language];
if (!messages) {
setError('No translations for language: ' + language);
return null;
}
var message = messages[messageKey];
if (!message) {
if (language === 'test') {
// Special case:
// The 'test' language just echoes the message key back out unless overridden.
return messageKey;
} else if (!optionalMessage) {
setError('No such message key: ' + messageKey);
}
return null;
}
return message;
}
function getDefaultDeletionScore(language) {
switch (String(language)) {
case 'cn':
return -2;
case 'vi':
return 0;
case 'fr':
case 'es':
return -3;
case 'en':
case 'pig':
default:
return -10;
}
}
function insertCSS(styling) {
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(styling));
head.appendChild(style);
}
// Timer creation
function buildUrl(language, startDate, durationMs, progressMessage, finishedMessage, styling) {
// Calculate target datetime
var targetDate = new Date(startDate.getTime() + durationMs);
// Finally, build URL
var parameters = new URLSearchParams();
parameters.append('lang', language);
parameters.append('time', targetDate.toISOString());
if (progressMessage) {
parameters.append('progress', progressMessage);
}
if (finishedMessage) {
parameters.append('finished', finishedMessage);
}
if (styling) {
parameters.append('style', styling);
}
return 'https://scpwiki.github.io/timer/timer.html?' + parameters;
}
function buildWikitext(language, template, url, score, height, width) {
function getSummaryDeletionText() {
var summaryDeletionBox = document.getElementById('summary-deletion-reason');
if (summaryDeletionBox.value) {
var retVal = " " + getMessage(language, 'summary-deletion-reason-skeleton');
var reason = summaryDeletionBox.options[summaryDeletionBox.selectedIndex].text;
return retVal.replace('%%reason%%', reason);
} else {
return "";
}
}
var iframe = [
'[[iframe ', url, ' style="width: ', width, '; height: ', height, '; border: 0; text-align: center;"]]',
].join('');
return template
.replace('%%url%%', url)
.replace('%%score%%', score)
.replace('%%iframe%%', iframe)
.replace('%%summary%%', getSummaryDeletionText());
}
function findCheckedItem(selector) {
var elements = document.querySelectorAll(selector);
for (var i = 0; i < elements.length; i++) {
if (elements[i].checked) {
return elements[i];
}
}
alert(getMessage(language, 'error-missing'));
throw new Error('Could not find a checked radio button item');
}
function getStartDate(language) {
var element = findCheckedItem('#start input');
switch (element.id) {
case 'start-now':
return new Date();
case 'start-later':
var dateElement = document.getElementById('start-later-date');
var timeElement = document.getElementById('start-later-time');
if (dateElement === null || timeElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing date or time element in getStartDate()');
}
return new Date(dateElement.value + ' ' + timeElement.value);
default:
alert(getMessage(language, 'error-invalid'));
throw new Error('Invalid element ID in getStartDate()');
}
}
function getDuration() {
var element = findCheckedItem('#duration input');
if (element.value !== 'custom') {
return parseInt(element.value);
}
var valueElement = document.getElementById('duration-custom-value');
var value = parseInt(valueElement.value);
if (isNaN(value)) {
alert(getMessage(language, 'error-missing'));
throw new Error('No value in custom duration selector');
}
var unitElement = document.getElementById('duration-custom-unit');
var unit = parseInt(unitElement.value);
return value * unit;
}
function getTextData(language) {
var progressElement = document.getElementById('message-progress');
if (progressElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing progress element in getTextData()');
}
var finishedElement = document.getElementById('message-finished');
if (finishedElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing finished element in getTextData()');
}
var heightElement = document.getElementById('height');
if (heightElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing height element in getTextData()');
}
var widthElement = document.getElementById('width');
if (widthElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing width element in getTextData()');
}
var customCssElement = document.getElementById('custom-css');
if (customCssElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing custom CSS element in getTextData()');
}
var templateElement = document.getElementById('template');
if (templateElement === null) {
alert(getMessage(language, 'error-missing'));
throw new Error('Missing template element in getTextData()');
}
return {
progressMessage: progressElement.value,
finishedMessage: finishedElement.value,
height: heightElement.value,
width: widthElement.value,
styling: customCssElement.value,
template: templateElement.value,
};
}
function buildTimer(language, copyToClipboard) {
// Unhide output
var outputElement = document.getElementById('output');
outputElement.classList.remove('hidden');
// Gather values
var startDate = getStartDate(language);
var durationMs = getDuration(language);
var data = getTextData(language);
var score = document.getElementById('deletion-score-value').value;
// Build wikitext and output
var url = buildUrl(
language,
startDate,
durationMs,
data.progressMessage,
data.finishedMessage,
data.styling,
);
outputElement.value = buildWikitext(language, data.template, url, score, data.height, data.width);
if (copyToClipboard) {
navigator.clipboard.writeText(outputElement.value);
}
}
function setMessage(language, id, messageKey = null) {
document.getElementById(id).innerText = getMessage(language, messageKey || id);
}
function initializeSummaryDeletionMessages(language) {
// Summary deletion reasons vary by site
var summaryDeletionBox = document.getElementById('summary-deletion-reason');
var messages = getMessage(language, 'summary-deletion-reasons', true);
for (var i = 0; i < messages.length; i++) {
var message = messages[i];
var opt = document.createElement('option');
opt.value = opt.innerHTML = message;
summaryDeletionBox.appendChild(opt);
}
// Only show summary deletion options if supported by the selected language
if (summaryDeletionBox.children.length > 1) {
setMessage(language, 'summary-deletion-label', 'summary-deletion');
setMessage(language, 'summary-deletion-reason-none');
} else {
summaryDeletionBox.hidden = true;
document.getElementById('summary-deletion-label').hidden = true;
}
}
// Initialization
function initializeMessages(language) {
setMessage(language, 'timer-type-label', 'timer-type');
setMessage(language, 'timer-type-generic-label', 'timer-type-generic');
setMessage(language, 'timer-type-deletion-label', 'timer-type-deletion');
setMessage(language, 'timer-type-ban-label', 'timer-type-ban');
setMessage(language, 'deletion-options-label', 'deletion-options');
setMessage(language, 'deletion-score-label', 'deletion-score');
setMessage(language, 'start-label', 'start-time');
setMessage(language, 'start-now-label', 'start-time-now');
setMessage(language, 'start-later-label', 'start-time-later');
setMessage(language, 'duration-label', 'duration');
setMessage(language, 'duration-1d-label', 'duration-1d');
setMessage(language, 'duration-1w-label', 'duration-1w');
setMessage(language, 'duration-2w-label', 'duration-2w');
setMessage(language, 'duration-1y-label', 'duration-1y');
setMessage(language, 'duration-custom-label', 'duration-custom');
setMessage(language, 'unit-minute');
setMessage(language, 'unit-hour');
setMessage(language, 'unit-day');
setMessage(language, 'unit-week');
setMessage(language, 'unit-month');
setMessage(language, 'unit-year');
setMessage(language, 'messages-label', 'messages');
document.getElementById('message-progress').placeholder = getMessage(language, 'timer-progress');
document.getElementById('message-finished').placeholder = getMessage(language, 'timer-finished');
setMessage(language, 'message-progress-label', 'message-progress');
setMessage(language, 'message-finished-label', 'message-finished');
setMessage(language, 'advanced-label', 'advanced-section');
setMessage(language, 'height-label', 'height');
setMessage(language, 'width-label', 'width');
setMessage(language, 'custom-css-label', 'css-extra');
setMessage(language, 'template-label', 'template');
document.getElementById('custom-css').placeholder = '#title {\n color: #008080;\n}';
setMessage(language, 'build', 'build-timer');
setMessage(language, 'copy', 'build-and-copy-timer');
setMessage(language, 'info-help');
setMessage(language, 'info-source');
initializeSummaryDeletionMessages(language);
}
function initializeDeletionScore(deletionScore) {
var scoreBox = document.getElementById('deletion-score-value');
scoreBox.value = deletionScore;
scoreBox.onclick = scoreBox.onblur = function() {
if (Number(scoreBox.value) > deletionScore) {
scoreBox.style.backgroundColor = "yellow";
} else {
scoreBox.style.backgroundColor = "white";
}
}
}
function initializeHooks(language) {
function toggleDeletionOptVisibility(show) {
var deletionOptElement = document.getElementById('deletion-options');
if (show) {
deletionOptElement.classList.remove('hidden');
} else {
deletionOptElement.classList.add('hidden');
}
}
document.getElementById('timer-type-generic').onclick = function () {
document.getElementById('message-progress').value = '';
document.getElementById('message-finished').value = '';
document.getElementById('template').value = '%%iframe%%';
toggleDeletionOptVisibility(false);
};
document.getElementById('timer-type-deletion').onclick = function () {
document.getElementById('duration-1d').click();
document.getElementById('message-progress').value = getMessage(language, 'message-deletion-progress');
document.getElementById('message-finished').value = getMessage(language, 'message-deletion-finished');
document.getElementById('template').value = getMessage(language, 'template-deletion');
toggleDeletionOptVisibility(true);
};
document.getElementById('timer-type-ban').onclick = function () {
document.getElementById('message-progress').value = getMessage(language, 'message-ban-progress');
document.getElementById('message-finished').value = getMessage(language, 'message-ban-finished');
document.getElementById('template').value = getMessage(language, 'template-ban');
toggleDeletionOptVisibility(false);
};
function onClickStartDate() {
document.getElementById('start-later').click();
}
document.getElementById('start-later-date').onclick = onClickStartDate;
document.getElementById('start-later-time').onclick = onClickStartDate;
function onClickCustom() {
document.getElementById('duration-custom').click();
}
document.getElementById('duration-custom-value').onclick = onClickCustom;
document.getElementById('duration-custom-unit').onclick = onClickCustom;
document.getElementById('build').onclick = function () {
buildTimer(language, false);
};
document.getElementById('copy').onclick = function () {
buildTimer(language, true);
};
}
function setup() {
// Get parameters
var url = new URL(window.location.href);
var parameters = new URLSearchParams(url.search);
var language = parameters.get('lang');
var styling = parameters.get('style');
var deletionScore = parameters.get('delScore');
// Check parameters
if (!language) {
setError('No language set', 'Parameter is "lang". Use "en" for English.');
return;
}
if (!deletionScore) {
deletionScore = getDefaultDeletionScore(language);
}
// Insert custom CSS, if any
if (styling !== null) {
insertCSS(styling);
}
initializeMessages(language);
initializeDeletionScore(deletionScore);
initializeHooks(language);
}
setTimeout(setup, 5);