forked from Metalloriff/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransitioningBackgrounds.plugin.js
513 lines (465 loc) · 29 KB
/
TransitioningBackgrounds.plugin.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
//META{"name":"TransitioningBackgrounds"}*//
class TransitioningBackgrounds {
constructor() {
this.defaultSettings = {
images : new Array(),
transitionMethod : "zoom-fade",
changeDelay : 30,
transitionTime : 3,
randomize : false,
onlyRunWhileFocused : false,
forceTransparency : false,
backgroundDarkness : 0.5
}
this.settings;
this.loop;
this.index;
this.focused = true;
this.removeTimeout;
}
getName() { return "Transitioning Backgrounds"; }
getDescription() { return "Allows you to set a list of backgrounds that will be transitioned between with several transition types, in order, or at random."; }
getVersion() { return "0.1.4"; }
getAuthor() { return "Metalloriff, Fixed by Subaru#1337"; }
load() {}
start() {
var libraryScript = document.getElementById('zeresLibraryScript');
if (!libraryScript) {
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://rauenzi.github.io/BetterDiscordAddons/Plugins/PluginLibrary.js");
libraryScript.setAttribute("id", "zeresLibraryScript");
document.head.appendChild(libraryScript);
}
if (typeof window.ZeresLibrary !== "undefined") this.initialize();
else libraryScript.addEventListener("load", () => { this.initialize(); });
}
getSettingsPanel(){
if(!$(".plugin-settings").length)
setTimeout(() => { this.getSettingsPanel(); }, 100);
else
this.createSettingsPanel();
}
createSettingsPanel(){
var panel = $(".plugin-settings");
if(panel.length){
panel.append(`
<style>
.tb-ticked {
background-color: white;
height: 60%;
width: 60%;
border-radius: 3px;
}
.tb-label {
color: white;
padding-bottom: 5px;
font-size: 20px;
}
</style>
<div class="plugin-settings" id="plugin-settings-Transitioning Backgrounds">
<h style="color: white;font-size: 30px;font-weight: bold;">Transitioning Backgrounds by Metalloriff</h>
<div style="padding-top: 20px;">
<h5 id="tb-images-label" class="tb-label">Background images</h5>
<div class="radioGroup-1GBvlr">
<div id="tb-image-array">
</div>
<div style="text-align: center;">
<button id="tb-add-image-button" style="display: inline-block; margin-right: 25px;" type="button" class="button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeMedium-1AC_Sl grow-q77ONN">
<div class="contents-4L4hQM">Add</div>
</button>
<button id="tb-clear-images-button" style="display: inline-block; margin-right: 25px;" type="button" class="button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeMedium-1AC_Sl grow-q77ONN">
<div class="contents-4L4hQM">Clear</div>
</button>
</div>
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Transition speed (seconds)</h5>
</div><input id="tb-transition-time" value="` + this.settings.transitionTime + `" type="number" class="inputDefault-_djjkz input-cIJ7To size16-14cGz5">
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Time between transitions (seconds)</h5>
</div><input id="tb-transition-delay" value="` + this.settings.changeDelay + `" type="number" class="inputDefault-_djjkz input-cIJ7To size16-14cGz5">
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Transition type</h5>
<div id="tb-trans-method-group" class="radioGroup-1GBvlr">
<div data-method="none" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">None</div>
</div>
</div>
<div data-method="fade" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Fade</div>
</div>
</div>
<div data-method="slide-left" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Slide left</div>
</div>
</div>
<div data-method="slide-right" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Slide right</div>
</div>
</div>
<div data-method="slide-up" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Slide up</div>
</div>
</div>
<div data-method="slide-down" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Slide down</div>
</div>
</div>
<div data-method="shrink" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Shrink</div>
</div>
</div>
<div data-method="rotate-x" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Rotate horizontally</div>
</div>
</div>
<div data-method="rotate-y" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Rotate vertically</div>
</div>
</div>
<div data-method="zoom-fade" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Zoom and fade</div>
</div>
</div>
</div>
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Image selection type</h5>
<div id="tb-selection-type" class="radioGroup-1GBvlr">
<div data-value="false" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">In order</div>
</div>
</div>
<div data-value="true" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Randomized</div>
</div>
</div>
</div>
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Other settings</h5>
<div id="tb-other-settings" class="radioGroup-1GBvlr">
<div data-key="onlyRunWhileFocused" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Only run while Discord is focused</div>
</div>
</div>
<div data-key="forceTransparency" class="item-26Dhrx marginBottom8-AtZOdT horizontal-2EEEnY flex-1O1GKY directionRow-3v3tfG cardPrimaryEditable-3KtE4g card-3Qj_Yx tb-radiobutton" style="padding: 10px;border-radius: 0px !important;">
<label class="checkboxWrapper-SkhIWG">
<input type="checkbox" class="inputDefault-3JxKJ2 input-3ITkQf" value="on">
<div class="checkbox-1ix_J3 flexCenter-3_1bcw flex-1O1GKY justifyCenter-3D2jYp alignCenter-1dQNNs box-mmYMsp">
</div>
</label>
<div class="info-3LOr12">
<div class="title-3BE6m5">Force transparency (may look bad. only use this if you have a theme with no background, or no theme.)</div>
</div>
</div>
</div>
</div>
<div style="padding-top: 20px;">
<h5 class="tb-label">Force transparency background darkness</h5>
</div><input id="tb-background-darkness" value="${this.settings.backgroundDarkness}" min="0" max="1" type="number" class="inputDefault-_djjkz input-cIJ7To size16-14cGz5">
</div>
</div>
<h5 class="tb-label" style="color: blueviolet;word-spacing: 5px;padding-top:30px;">Hint: you can edit the background element using the .transitioning-background class, and you can change the behaviour of each fade method with CSS as well.
Search the inspector for "TransitioningBackgrounds" to see all available classes.</h5>
`);
var updateTransitionMethod = () => {
$(".tb-radiobutton-ticked-transmethod").remove();
$("[data-method='" + this.settings.transitionMethod + "'] > label > div").append(`<div class="tb-ticked tb-radiobutton-ticked-transmethod"></div>`);
};
updateTransitionMethod();
$("#tb-trans-method-group > .tb-radiobutton").on("click", e => {
this.settings.transitionMethod = $(e.currentTarget).data("method");
updateTransitionMethod();
this.saveSettings();
});
var updateSelectionType = () => {
$(".tb-selection-type-ticked").remove();
$("#tb-selection-type > div:nth-child(" + (this.settings.randomize ? 2 : 1) + ") > label > div").append(`<div class="tb-ticked tb-selection-type-ticked"></div>`);
};
updateSelectionType();
$("#tb-selection-type > div").on("click", e => {
this.settings.randomize = $(e.currentTarget).data("value");
updateSelectionType();
this.saveSettings();
});
var otherSettings = $("#tb-other-settings > div");
var updateOtherSettings = () => {
$(".tb-other-settings-ticked").remove();
for(var i = 0; i < otherSettings.length; i++){
var key = $(otherSettings[i]).data("key");
if(this.settings[key])
$("[data-key='" + key + "'] > label > div").append(`<div class="tb-ticked tb-other-settings-ticked"></div>`);
}
};
updateOtherSettings();
$("#tb-other-settings > div").on("click", e => {
this.settings[$(e.currentTarget).data("key")] = !this.settings[$(e.currentTarget).data("key")];
updateOtherSettings();
this.saveSettings();
});
var saveImages = () => {
var inputs = $(".tb-image-array-item > input");
this.settings.images = Array.from(inputs.toArray(), x => x.value);
for(var i = 0; i < inputs.length; i++){ inputs[i].style.backgroundImage = "url('" + this.settings.images[i] + "')"; }
this.saveSettings();
};
var updateImageList = () => {
$(".tb-image-array-item").remove();
for(var i = 0; i < this.settings.images.length; i++){
$("#tb-image-array").append(`
<div class="tb-image-array-item" style="padding-bottom: 10px;">
<input value="` + this.settings.images[i] + `" class="inputDefault-_djjkz input-cIJ7To size16-14cGz5" style="display: inline-block;width: 500px;background-image: url('` + this.settings.images[i] + `');background-size: cover;">
<button id="tb-remove-image-button-` + i + `" style="display: inline-block;margin-right: 25px;float: right;" type="button" class="button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeMedium-1AC_Sl grow-q77ONN">
<div class="contents-4L4hQM">Remove</div>
</button>
</div>
`);
}
$(".tb-image-array.item > input").off("focusout");
$(".tb-image-array-item > button").off("click");
$(".tb-image-array-item > input").on("focusout", () => { saveImages(); });
$(".tb-image-array-item > button").on("click", e => {
$(e.currentTarget.parentElement).remove();
saveImages();
});
}
updateImageList();
$("#tb-clear-images-button").on("click", () => {
$(".tb-image-array-item").remove();
saveImages();
});
$("#tb-add-image-button").on("click", () => {
this.settings.images.push("");
updateImageList();
});
$("#tb-transition-time").on("focusout", () => {
this.settings.transitionTime = document.getElementById("tb-transition-time").value;
this.saveSettings();
});
$("#tb-transition-delay").on("focusout", () => {
this.settings.changeDelay = document.getElementById("tb-transition-delay").value;
this.saveSettings();
});
$("#tb-background-darkness").on("focusout", () => {
this.settings.backgroundDarkness = document.getElementById("tb-background-darkness").value;
this.saveSettings();
});
}else
this.getSettingsPanel();
}
saveSettings(reload = true){
PluginUtilities.saveSettings("TransitioningBackgrounds", this.settings);
if(reload)
this.apply();
}
initialize(){
PluginUtilities.checkForUpdate(this.getName(), this.getVersion(), "https://github.com/Metalloriff/BetterDiscordPlugins/raw/master/TransitioningBackgrounds.plugin.js");
this.settings = PluginUtilities.loadSettings("TransitioningBackgrounds", this.defaultSettings);
$(window).on("focus.TransitioningBackgrounds", () => { this.focused = true; });
$(window).on("blur.TransitioningBackgrounds", () => { this.focused = false; });
$(document).on("contextmenu.TransitioningBackgrounds", e => { this.onContextMenu(e); })
this.apply();
}
apply(){
clearInterval(this.loop);
clearTimeout(this.removeTimeout);
$(".transitioning-background").remove();
if(this.settings.images.length == 0){
if(!$(".plugin-settings").length)
PluginUtilities.showToast("You have no images added to your backgrounds list! Add some in the plugin settings.");
return;
}
BdApi.clearCSS("TransitioningBackgrounds");
BdApi.injectCSS("TransitioningBackgrounds", `
.app { background: none !important; }
.transitioning-background {
background-size: cover;
width: 100%;
height: 100%;
position: absolute;
transition: all ` + this.settings.transitionTime + `s ease-in-out;
}
.tb-fade { opacity: 0; }
.tb-slide-left { transform: translateX(-100%); }
.tb-slide-right { transform: translateX(100%); }
.tb-slide-up { transform: translateY(-100%); }
.tb-slide-down { transform: translateY(100%); }
.tb-shrink { transform: scale(0); }
.tb-rotate-x { transform: rotateX(180deg); }
.tb-rotate-y { transform: rotateY(180deg); }
.tb-zoom-fade { transform: scale(5); opacity: 0; }
`);
BdApi.clearCSS("TransitioningBackgroundsTransparency");
if(this.settings.forceTransparency){
BdApi.injectCSS("TransitioningBackgroundsTransparency", `
.container-2lgZY8, .layer-3QrUeG, .ui-standard-sidebar-view {
background: rgba(0, 0, 0, ${this.settings.backgroundDarkness}) !important;
}
.layer-3QrUeG, .guildsWrapper-5TJh6A, .applicationStore-1pNvnv, .theme-dark .header-39GIC8, .gameUpdates-2GPqBU, .gameLibrary-TTDw4Y, .table-1tDS6w , .layers-3iHuyZ, .guilds-wrapper, .channels-Ie2l6A, .theme-dark .chat-3bRxxu, .title-3qD0b-, .theme-dark .content-yTz4x3, .theme-dark .messagesWrapper-3lZDfY, .theme-dark .chat-3bRxxu form, .sidebar-region, .content-region, .scroller-2FKFPG, .container-PNkimc, .container-PNkimc, #friends, .headerBar-UHpsPw, .friends-table, .theme-dark .activityFeed-28jde9, .typing-2GQL18 {
background: transparent !important;
background-color: transparent !important;
}
::-webkit-scrollbar-track-piece {
background: rgba(0, 0, 0, ${this.settings.backgroundDarkness}) !important;
border: none !important;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.15) !important;
border: none !important;
}
::-webkit-scrollbar-thumb:hover {
background: #7289da !important;
}
#app-mount .message-group .comment .markup, .nameUnreadText-DfkrI4, .nameUnreadVoice-EVo-wI {
color: white;
}
.nameDefaultText-24KCy5, .nameDefaultVoice-3WUH7s, .nameLockedText-3pqQcL, .nameLockedVoice-26MhB1 {
color: rgba(255, 255, 255, 0.75);
}
.icon-sxakjD, .icon-sxakjD path {
opacity: 1;
}
`);
}
this.index = 0;
this.loop = setInterval(() => { this.updateBackground(); }, this.settings.changeDelay * 1000);
this.updateBackground();
}
updateBackground(){
if(this.settings.images.length == 0 || (this.settings.onlyRunWhileFocused && !this.focused))
return;
var app = $(".app").first(), existingBackgrounds = $(".transitioning-background"), nextIndex = this.index + 1 >= this.settings.images.length ? 0 : this.index + 1;
if(this.settings.randomize)
nextIndex = this.settings.images.length * Math.random() << 0;
if(existingBackgrounds.length){
existingBackgrounds[1].className += " tb-" + this.settings.transitionMethod;
this.removeTimeout = setTimeout(() => {
$(existingBackgrounds[1]).remove();
app.prepend(`<div class="transitioning-background" style="background-image: url('` + this.settings.images[nextIndex] + `')"></div>`);
}, this.settings.transitionTime * 1000);
}else{
app.prepend(`<div class="transitioning-background" style="background-image: url('` + this.settings.images[this.index] + `')"></div>`);
app.prepend(`<div class="transitioning-background" style="background-image: url('` + this.settings.images[nextIndex] + `')"></div>`);
}
this.index = nextIndex;
}
onContextMenu(e){
var image = undefined, elementURL = undefined, itemGroups = $(".itemGroup-1tL0uz");
if(e.target.localName == "a"){ elementURL = e.target.href; }
if(e.target.localName == "img"){ elementURL = e.target.src; }
if(elementURL == undefined){ return; }
if(elementURL.lastIndexOf("?") != -1){ elementURL = elementURL.substring(0, elementURL.lastIndexOf("?")); }
if(elementURL.endsWith(".jpg") || elementURL.endsWith(".png") || elementURL.endsWith(".gif") || elementURL.endsWith(".jpeg")){ image = elementURL; }
$("#tb-contextmenu-addremove").remove();
if(image != undefined && itemGroups.length){
if(this.settings.images.includes(image)){
$(`<div id="tb-contextmenu-addremove" class="itemGroup-1tL0uz"><div class="item-1Yvehc"><span>Remove Background</span></div></div>`).insertBefore(itemGroups.first());
$("#tb-contextmenu-addremove").on("click", () => {
this.settings.images.splice(this.settings.images.indexOf(image), 1);
this.saveSettings(false);
PluginUtilities.showToast("Image removed from background list!", { type : "success" });
this.onContextMenu(e);
});
}else{
$(`<div id="tb-contextmenu-addremove" class="itemGroup-1tL0uz"><div class="item-1Yvehc"><span>Add As Background</span></div></div>`).insertBefore(itemGroups.first());
$("#tb-contextmenu-addremove").on("click", () => {
this.settings.images.push(image);
this.saveSettings(false);
PluginUtilities.showToast("Image added to background list!", { type : "success" });
this.onContextMenu(e);
});
}
}
}
stop() {
clearInterval(this.loop);
clearTimeout(this.removeTimeout);
$(window).off("focus.TransitioningBackgrounds");
$(window).off("blur.TransitioningBackgrounds");
$(document).off("contextmenu.TransitioningBackgrounds");
BdApi.clearCSS("TransitioningBackgroundsTransparency");
BdApi.clearCSS("TransitioningBackgrounds");
}
}