-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserscript_mastodon-topbar-nav.js
556 lines (473 loc) · 16.9 KB
/
userscript_mastodon-topbar-nav.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
// ==UserScript==
// @name Mastodon top bar navigation
// @namespace github.com/openstyles/stylus
// @version 1.0.0
// @description Top bar navigation for Mastodon in non-advanced mode. Feed is wider. UI is square.
// @author AlexTECPlayz
// @match *://*techhub.social/*
// @match *://*mastodon.social/*
// @match *://*mstdn.social/*
// @match *://*mastodon.world/*
// @match *://*mas.to/*
// @match *://*mastodon.online/*
// @match *://*mastodonapp.uk/*
// @match *://*universeodon.com/*
// @match *://*social.vivaldi.net/*
// @match *://*c.im/*
// @match *://*mstdn.party/*
// @match *://*det.social/*
// @match *://*ohai.social/*
// @match *://*toot.community/*
// @match *://*masto.nu/*
// @match *://*ieji.de/*
// @match *://*nerdculture.de/*
// @match *://*toot.io/*
// @match *://*mstdn.plus/*
// @match *://*persiansmastodon.com/*
// @match *://*stranger.social/*
// @match *://*cupoftea.social/*
// @match *://*famichiki.jp/*
// @match *://*fairy.id/*
// @match *://*convo.casa/*
// @match *://*expressional.social/*
// @match *://*opalstack.social/*
// @match *://*toot.funami.tech/*
// @match *://*cr8r.gg/*
// @match *://*sakurajima.moe/*
// @match *://*sself.co/*
// @match *://*mstdn.dk/*
// @match *://*beekeeping.ninja/*
// @match *://*tooters.org/*
// @match *://*mstdn.business/*
// @match *://*masto.ai/*
// @match *://*hachyderm.io/*
// @match *://*defcon.social/*
// @match *://*bark.lgbt/*
// @match *://*tech.lgbt/*
// @match *://*meow.social/*
// @match *://*yiff.life/*
// @match *://*mastodon.art/*
// @match *://*comfy.social/*
// @match *://*mamot.fr/*
// @match *://*fedi.software/*
// @match *://*fightforthefuture.org/*
// @match *://*social.network.europa.eu/*
// @match *://*tube.network.europa.eu/*
// @match *://*wikimedia.social/*
// @match *://*social.overheid.nl/*
// @match *://*mastodon.green/*
// @match *://*botany.social/*
// @match *://*wetdry.world/*
// @match *://*mastodon.xyz/*
// @match *://*social.openrights.org/*
// @match *://*aus.social/*
// @match *://*mastodon.gamedev.place/*
// @match *://*chaosfem.tw/*
// @match *://*mas.to/*
// @match *://*floss.social/*
// @match *://*mastodon.au/*
// @match *://*mastodon.sdf.org/*
// @match *://*mozilla.social/*
// @match *://*wikis.world/*
// @match *://*fosstodon.org/*
// @match *://*mastodon.matrix.org/*
// @match *://*raspberrypi.social/*
// @match *://*framapiaf.org/*
// @match *://*infosec.exchange/*
// @match *://*dice.camp/*
// @match *://*social.growyourown.services/*
// @match *://*neat.computer/*
// @match *://*ubuntu.social/*
// @match *://*social.lol/*
// @match *://*s.awoo.social/*
// @match *://*med-mastodon.com/*
// @match *://*bitbang.social/*
// @match *://*digipres.club/*
// @match *://*treehouse.systems/*
// @match *://*indieweb.social/*
// @match *://*queer.party/*
// @match *://*social.theboxcollective.org/*
// @match *://*kitty.social/*
// @match *://*campaign.openworlds.info/*
// @match *://*oldbytes.space/*
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
var style = document.createElement('style');
style.textContent = `
body:not(.layout-multiple-columns) {
@media only screen and (min-width: 1175px) {
.navigation-panel {
display: flex !important;
flex-direction: row !important;
justify-content: center;
align-items: start;
padding: 0rem;
top: 0;
left: 0;
}
.navigation-panel__logo {
display: none;
}
.navigation-panel a {
margin-top: 0rem;
margin-bottom: 0rem;
margin-left: 0.5rem;
margin-right: 0.5rem;
text-decoration: none !important;
}
.navigation-bar {
margin: -1rem;
position: unset;
z-index: 2;
}
.column-link {
font-size: 14px;
padding: 10px;
}
.column-link--transparent.active {
background-color: #8c8dff;
color: #fff;
}
.getting-started__trends {
display: none;
}
.columns-area__panels__pane {
min-width: 585px;
display: unset;
}
.columns-area__panels__main {
min-width: 600px;
max-width: 180vh;
position: absolute;
top: 0;
}
.search {
margin: 0.35rem;
}
.compose-panel {
display: none;
width: 100%;
margin: 0rem;
height: unset;
}
.compose-panel .navigation-bar {
top: 0;
right: 0;
position: absolute;
margin-top: -0.5rem;
}
.compose-panel .compose-form {
display: flex;
flex-direction: row;
min-height: unset;
min-width: unset;
padding: 0rem;
margin: 0rem;
justify-content: center;
}
.compose-panel .link-footer {
display: none;
}
.columns-area__panels__pane__inner {
display: unset;
}
.topnav-container {
display: flex;
width: 100%;
justify-content: space-evenly;
position: sticky;
top: 0;
z-index: 10;
background-color: rgba(25, 27, 34, 0.5);
}
.tabs-bar__wrapper {
padding-top: 60px;
top: 0;
z-index: 2;
}
.compose-button {
display: block;
padding: 10px;
}
.compose-button__button {
font-size: 14px;
padding: 11.5px;
text-decoration: none !important;
margin: 0rem;
background-color: #6364ff;
color: #fff;
border: none;
}
.compose-button__button:hover {
background-color: #8c8dff;
}
.compose-container {
display: block;
background-color: transparent;
position: relative;
z-index: 3;
margin-bottom: -2.5rem;
}
.columns-area__panels {
display: block;
}
.compose-form {
display: flex;
flex-direction: row;
}
.compose-form__autosuggest-wrapper {
display: flex;
}
.autosuggest-textarea {
display: flex;
flex-direction: row;
width: unset;
}
.compose-form .autosuggest-textarea__textarea {
min-height: 1px;
border-radius: 0px;
}
.autosuggest-textarea__textarea {
min-height: 1px;
border-radius: 0px;
width: 100%;
height: auto;
padding-top: 0.35rem;
}
.compose-form .autosuggest-input, .compose-form .autosuggest-textarea, .compose-form .spoiler-input {
width: unset;
}
.compose-form .compose-form__publish .compose-form__publish-button-wrapper {
padding-top: 0rem;
}
.compose-panel .compose-form__autosuggest-wrapper {
border-radius: 0px;
}
.compose-form .compose-form__buttons-wrapper {
border-radius: 0px;
}
.compose-form__publish-button-wrapper {
padding-top: unset;
padding-left: 0.5rem;
}
.button.button--block {
height: 100%;
border-radius: 0px;
}
.character-counter {
line-height: 27px;
}
.compose-form .emoji-picker-dropdown {
padding: 0.5rem;
}
.status-card__image-image {
border-radius: 0px !important;
}
}
}`;
document.head.appendChild(style);
var newContainer_Topbar = document.createElement("div");
var newContainer_Compose = document.createElement("div");
newContainer_Topbar.classList.add("topnav-container");
newContainer_Compose.classList.add("compose-container");
var observer;
var topnavContainer = document.querySelector(".topnav-container");
function setStickyPosition() {
if (!topnavContainer) return;
var scrollY = window.scrollY || window.pageYOffset;
var threshold = 1;
if (scrollY >= threshold) {
topnavContainer.style.position = 'fixed';
topnavContainer.style.top = '0';
} else {
topnavContainer.style.position = 'static';
}
}
function removeDivsByClass(className) {
var elementsToRemove = document.querySelectorAll('.' + className);
elementsToRemove.forEach(function(element) {
element.remove();
});
}
function addComposeButton() {
var composePanel = document.querySelector(".topnav-container");
if (composePanel) {
var composeButtonDiv = document.createElement("div");
composeButtonDiv.classList.add("compose-button");
var composeButton = document.createElement("button");
composeButton.textContent = "Compose";
composeButton.classList.add("compose-button__button");
composeButton.addEventListener("click", function() {
var composeForm = document.querySelector(".compose-panel");
if (composeForm) {
if (composeForm.style.display === "block") {
composeForm.style.display = "none";
} else {
composeForm.style.display = "block";
window.scrollTo({
top: 0,
behavior: "smooth"
});
}
}
});
composeButtonDiv.appendChild(composeButton);
composePanel.appendChild(composeButtonDiv);
}
}
function moveElements() {
if (newContainer_Topbar.parentNode) {
return;
}
newContainer_Topbar.innerHTML = '';
newContainer_Compose.innerHTML = '';
var elementsToMove_Topbar = document.querySelectorAll(".navigation-panel, .search, .navigation-bar");
var elementsToMove_Compose = document.querySelectorAll(".compose-panel");
elementsToMove_Topbar.forEach(function(element) {
newContainer_Topbar.appendChild(element);
});
elementsToMove_Compose.forEach(function(element) {
newContainer_Compose.appendChild(element);
});
var mainContent = document.querySelector(".tabs-bar__wrapper");
if (mainContent) {
mainContent.parentNode.insertBefore(newContainer_Topbar, mainContent);
mainContent.parentNode.insertBefore(newContainer_Compose, mainContent);
if (observer) {
observer.disconnect();
}
removeDivsByClass('ui__header');
removeDivsByClass('link-footer');
removeDivsByClass('navigation-panel__logo');
removeDivsByClass('columns-area__panels__pane--start');
removeDivsByClass('columns-area__panels__pane--navigational');
removeDivsByClass('logo-resources');
removeDivsByClass('navigation-panel__sign-in-banner');
var searchPanel = newContainer_Topbar.querySelector(".search");
var navigationPanel = newContainer_Topbar.querySelector(".navigation-panel");
var navigationBar = newContainer_Topbar.querySelector(".navigation-bar");
newContainer_Topbar.appendChild(newContainer_Topbar.querySelector(".navigation-panel"));
newContainer_Topbar.appendChild(newContainer_Topbar.querySelector(".search"));
addComposeButton();
newContainer_Topbar.appendChild(newContainer_Topbar.querySelector(".navigation-bar"));
var composePanel = newContainer_Compose.querySelector(".compose-panel");
newContainer_Compose.appendChild(newContainer_Compose.querySelector(".compose-panel"));
removeDivsByClass('columns-area__panels__pane');
removeDivsByClass('columns-area__panels__pane__inner');
setStickyPosition();
window.addEventListener('scroll', setStickyPosition);
}
}
function getLuminance(color) {
const rgb = color.match(/\d+/g);
if (!rgb || rgb.length < 3) return 0;
const r = parseInt(rgb[0]) / 255;
const g = parseInt(rgb[1]) / 255;
const b = parseInt(rgb[2]) / 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
return ((max + min) / 2) * 100;
}
function adjustColorBrightness(color, desiredLuminance) {
const currentLuminance = getLuminance(color);
const luminanceDifference = desiredLuminance - currentLuminance;
const factor = 1 + (luminanceDifference / 100); // Adjust this multiplier as needed
const adjustedColor = color.match(/\d+/g).map(channel => {
return Math.min(255, parseInt(channel * factor));
});
return `rgb(${adjustedColor.join(',')})`;
}
function adjustTextColor(backgroundColor) {
const luminance = getLuminance(backgroundColor);
if (luminance > 50) {
return 'black;';
} else {
return 'white;';
}
}
function getUserBannerImageUrl() {
var bannerImage = document.querySelector(".parallax");
if (bannerImage) {
var bannerImageUrl = bannerImage.src;
function getDominantColor(imageUrl, callback) {
var img = new Image();
img.crossOrigin = "Anonymous";
img.src = imageUrl;
img.onload = function () {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
var colorCounts = {};
var maxColor = null;
var maxCount = 0;
for (var i = 0; i < imageData.length; i += 4) {
var r = imageData[i];
var g = imageData[i + 1];
var b = imageData[i + 2];
var color = `rgb(${r},${g},${b})`;
if (colorCounts[color]) {
colorCounts[color]++;
} else {
colorCounts[color] = 1;
}
if (colorCounts[color] > maxCount) {
maxColor = color;
maxCount = colorCounts[color];
}
}
callback(maxColor);
};
}
getDominantColor(bannerImageUrl, function (color) {
var desiredLuminance = 350; // Adjust this as needed
var adjustedColor = adjustColorBrightness(color, desiredLuminance);
var textColorStyle = adjustTextColor(adjustedColor);
var style = document.createElement("style");
style.textContent = `
.accent-color-bg {
background-color: ${textColorStyle};
color: ${adjustedColor};
}
.accent-color-col {
color: ${textColorStyle};
background-color: ${adjustedColor};
}
.account__header__tabs__name small span {
background-color: ${adjustedColor};
color: ${textColorStyle};
}
dl[class=""] > dd.translate > span >a > span[class=""] {
background: ${adjustedColor};
color: ${textColorStyle};
}
.account__header__tabs__buttons > button.button.logo-button {
background: ${adjustedColor};
color: ${textColorStyle};
}`;
document.head.appendChild(style);
});
} else {
console.log("Banner image element not found.");
}
}
setTimeout(function() {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
topnavContainer = document.querySelector(".topnav-container");
moveElements();
setTimeout(getUserBannerImageUrl, 1500); // Adjust the delay as needed
});
} else {
setTimeout(getUserBannerImageUrl, 1500); // Adjust the delay as needed
topnavContainer = document.querySelector(".topnav-container")
moveElements();
}
observer = new MutationObserver(moveElements);
observer.observe(document.body, {childList: true, subtree: true });
}, 1000);
})();