Skip to content

Commit d5a3218

Browse files
authored
Update unity-forum-fixer.js
Make notification panel icons more juicy!
1 parent a2e5a8b commit d5a3218

File tree

1 file changed

+114
-7
lines changed

1 file changed

+114
-7
lines changed

‎unity-forum-fixer.js

+114-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name UnityForumFixer
33
// @namespace https://unitycoder.com/
4-
// @version 0.73 (16.12.2024)
4+
// @version 0.8 (21.12.2024)
55
// @description Fixes For Unity Forums - https://github.com/unitycoder/UnityForumFixer
66
// @author unitycoder.com
77
// @match https://discussions.unity.com/latest
@@ -25,9 +25,23 @@
2525
TopicsViewCombineViewAndReplyCounts();
2626
OnMouseOverPostPreview();
2727

28-
setTimeout(OnUpdate, 1000); // run loop to update activity times (since some script changes them back to original..)
28+
// update notification panel icons
29+
const currentUserButton = document.getElementById('toggle-current-user');
30+
if (currentUserButton) {
31+
currentUserButton.addEventListener('click', () => {
32+
console.log(1111);
33+
// Add a slight delay to ensure the dropdown content is fully rendered
34+
setTimeout(replaceNotificationIcons, 1000);
35+
});
36+
} else {
37+
console.warn('Current user button not found.');
38+
}
39+
40+
41+
setTimeout(OnUpdate, 1000); // run loop to update certain itesm (since something is updating them, without page refresh..)
2942
});
3043

44+
3145
})();
3246

3347
// runs every second to update things (if you scroll the page, need to update new data)
@@ -39,6 +53,9 @@ function OnUpdate()
3953
PostViewShowOriginalPosterInfo();
4054
PostViewFetchOPDetails();
4155

56+
// TODO only refresh these when notification panel is opened
57+
//replaceNotificationIcons();
58+
4259
setTimeout(OnUpdate, 1000);
4360
}
4461

@@ -50,9 +67,12 @@ function AppendCustomCSS()
5067
var style = document.createElement('style');
5168
style.textContent =
5269
`
53-
// latest posts view
54-
.show-more.has-topics { width: 35%;!important;} /* updated topics alert */
55-
.alert.alert-info.clickable {width: 35%; padding:3px !important;} /* updated topics alert */
70+
/* top banner */
71+
.before-header-panel-outlet { text-align: center; }
72+
.show-more.has-topics { width: 35% !important; }
73+
/* latest posts view */
74+
.show-more.has-topics { width: 35%;!important;}
75+
.alert.alert-info.clickable {width: 35%; padding:3px !important;}
5676
5777
#main-outlet {width:auto !important;} /* smaller main forum width */
5878
@@ -102,7 +122,7 @@ function AppendCustomCSS()
102122
.user-name { margin-bottom: 5px; font-weight: bold; text-align: center; font-size: 0.9em; color: var(--primary); text-decoration: none; display: block; word-wrap: break-word; white-space: normal; width: 100%; }
103123
.user-name:hover { color: rgb(82,132,189); text-decoration: underline; }
104124
.names.trigger-user-card {visibility: hidden !important;}
105-
/* .row { display: flex; } */
125+
/* .row { display: flex; } */
106126
.topic-avatar { flex-basis: 10%; margin:0 !important; max-width: 45px;}
107127
.topic-body { flex-basis: 90%; } /* Ensure the main content adjusts accordingly */
108128
.topic-avatar {background-color: #d1d1d132;}
@@ -139,6 +159,7 @@ function AppendCustomCSS()
139159
.custom-post-username {margin-bottom:3px;color: var(--primary);}
140160
.custom-user-creation-date {width:45px;margin-top:6px;font: 13px 'Inter', sans-serif !important; color: rgb(150, 150, 150);}
141161
.custom-post-preview { position: absolute; max-width: 450px; max-height: 200px; background-color: var(--primary-low); border: 1px solid black; padding: 5px; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); z-index: 1000; }
162+
142163
143164
`;
144165
document.head.appendChild(style);
@@ -464,7 +485,7 @@ function PostViewFetchOPDetails()
464485

465486
// Check if the current page URL has already been processed
466487
if (currentPageURL === prevPageURL) {
467-
console.log(`Skipping fetch for already processed page URL: ${currentPageURL}`);
488+
//console.log(`Skipping fetch for already processed page URL: ${currentPageURL}`);
468489
return; // Skip execution if the URL has already been processed
469490
}
470491

@@ -547,6 +568,92 @@ window.addEventListener('pushstate', function() {PostViewFetchOPDetails();});
547568
window.addEventListener('replacestate', function() {PostViewFetchOPDetails();});
548569
*/
549570

571+
// new post icon in followed topic
572+
function replaceNotificationIcons() {
573+
// Define configuration for each notification type
574+
const notificationConfig = [
575+
{
576+
selector: '.notification.read.posted',
577+
textContent: '1',
578+
backgroundColor: 'rgba(255, 0, 0, 0.6)',
579+
color: 'white',
580+
borderRadius: '50%',
581+
fontSize: '12px'
582+
},
583+
{
584+
selector: '.notification.read.reaction',
585+
textContent: '👍',
586+
backgroundColor: 'none',
587+
color: 'white',
588+
borderRadius: '4px',
589+
fontSize: '1.25em'
590+
},
591+
{
592+
selector: '.notification.read.mentioned',
593+
textContent: '@',
594+
backgroundColor: 'none',
595+
color: 'var(--success)',
596+
borderRadius: '4px',
597+
fontSize: '1.25em'
598+
},
599+
{
600+
selector: '.notification.read.replied',
601+
textContent: '↩️',
602+
backgroundColor: 'none',
603+
color: 'white',
604+
borderRadius: '4px',
605+
fontSize: '1.25em'
606+
},
607+
{
608+
selector: '.notification.read.granted-badge',
609+
textContent: '🏆',
610+
backgroundColor: 'none',
611+
color: 'white',
612+
borderRadius: '4px',
613+
fontSize: '1.25em'
614+
},
615+
];
616+
617+
// Process each notification type
618+
notificationConfig.forEach(({ selector, textContent, backgroundColor, color, borderRadius, fontSize }) => {
619+
const notificationItems = document.querySelectorAll(selector);
620+
621+
if (notificationItems.length > 0) {
622+
notificationItems.forEach((item) => {
623+
const icon = item.querySelector('svg.fa.d-icon');
624+
if (icon) {
625+
// Create a replacement element
626+
const newIcon = document.createElement('div');
627+
newIcon.style.cssText = `
628+
display: inline-flex !important;
629+
justify-content: center !important;
630+
align-items: center !important;
631+
background-color: ${backgroundColor};
632+
color: ${color};
633+
font-size: ${fontSize};
634+
font-weight: bold;
635+
padding: 5px !important;
636+
box-sizing: border-box !important;
637+
width: 20px;
638+
height: 20px;
639+
min-width: 20px;
640+
min-height: 20px;
641+
line-height: 1;
642+
margin-right: 8px;
643+
border-radius: ${borderRadius} !important;
644+
text-align: center;
645+
`;
646+
newIcon.textContent = textContent;
647+
648+
// Replace the original SVG icon
649+
icon.replaceWith(newIcon);
650+
}
651+
});
652+
}
653+
});
654+
}
655+
656+
550657

551658

552659
// HELPER METHODS

0 commit comments

Comments
 (0)