Skip to content

Commit 69149c5

Browse files
authored
Update unity-forum-fixer.js
1 parent 76d5935 commit 69149c5

File tree

1 file changed

+112
-25
lines changed

1 file changed

+112
-25
lines changed

unity-forum-fixer.js

Lines changed: 112 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
AddAssetStoreLink();
2020
// ShowOriginalPosterInfo(); // TODO needs some css adjustments for name location
2121
//setTimeout(test, 1000);
22-
22+
FixPostActivityTime();
23+
setTimeout(OnUpdate, 1000); // run loop to update activity times (since some script changes them back to original..)
24+
NavBar();
2325
});
2426
})();
2527

26-
28+
function OnUpdate()
29+
{
30+
FixPostActivityTime();
31+
setTimeout(OnUpdate, 1000);
32+
}
2733

2834
function AppendCustomCSS()
2935
{
@@ -32,15 +38,35 @@ function AppendCustomCSS()
3238
style.textContent =
3339
`
3440
.wrap.custom-search-banner-wrap h1 {display: none;} /* hide welcome banner */
35-
.wrap.custom-search-banner-wrap {padding:0px;} /* search bar padding */
41+
.wrap.custom-search-banner-wrap {padding:0px;} /* remove search bar padding */
3642
:root {--d-background-image: none !important;} /* hide big bg image */
3743
* { border-radius: 0 !important; } /* remove ALL rounded edges, note user icons are now boxes too - might change it later */
3844
.fa.d-icon.d-icon-far-eye.svg-icon.svg-string {display: none !important;} /* hide views icon */
3945
.fa.d-icon.d-icon-comments.svg-icon.svg-string {display: none !important;} /* hide replies icon */
4046
.btn.no-text.btn-icon.cookie-settings.btn-flat.onetrust-cookie-settings-toggle {display: none !important;} /* hide cookie button from premium location */
41-
.results {margin-top:1px; background-color:#443e3e !important;} /* move search dropdown, so that it doesnt block search bar bottom */
47+
.results {margin-top:1px; } /* move search dropdown, so that it doesnt block search bar bottom */
4248
.search-menu-recent {font-size:0.8em !important;} /* recent searches font size */
43-
.search-menu .search-link:hover,.search-menu .search-link:focus,.search-menu-container.search-link:hover,.search-menu-container.search-link:focus {background-color: #5693b0 !important} /* recent searches hover color */
49+
.search-menu .search-link:hover,.search-menu .search-link:focus,.search-menu-container.search-link:hover,.search-menu-container.search-link:focus {background-color: #5693b0 !important} /* recent searches hover color to something reasonable */
50+
.is-solved-label.solved {font-weight: normal !important; font-size: 12px !important; padding: 1px !important; user-select: text !important; float: right !important; } /* resolved tag, initial fixes */
51+
.badge-category__icon {display: none !important;} /* hide badge category icon for now, since most of them seem to be unity logos */
52+
.is-solved-label {display: none !important;} /* hide unresolved span, since all are unresolved, unless marked solved? */
53+
.title.raw-link.raw-topic-link {font: bold 14px/1.231 arial,helvetica,clean,sans-serif !important;} /* post title: orig forum has 13px, might use that later */
54+
.title.raw-link.raw-topic-link:hover {color: rgb(82,132,189) !important; text-decoration: underline !important;} /*post title hover */
55+
.topic-list .topic-list-data:first-of-type {padding-left: 8px !important;} /* post topic rows, half the padding */
56+
.discourse-tags {font-size: 0.8em !important;} /* tags below post title, smaller */
57+
.post-activity {font-size: 0.9em !important;}
58+
.ember-view.bread-crumbs-left-outlet.breadcrumb-label {display: none !important;} /* "… or filter the topics via" */
59+
.navigation-container {--nav-space: 0 !important; padding-bottom: 6px;} /* navbar adjustments */
60+
.category-breadcrumb.ember-view {width:auto !important;} /* areas,categories,tags not 100% width */
61+
.navigation-controls { display: flex; justify-content: flex-end; width: 100%; } /* move new topic button to right, still would be nice to have in same row as other nav */
62+
.select-kit-row .desc { font-size: 0.92em !important; margin-top:1px; color: #777777 !important; } /* new topic dropdown descriptions */
63+
64+
.custom-search-banner-wrap > div {max-width:100% !important;} /* search bar maxwidth, need to find better location later */
65+
.sidebar-wrapper {width: 222px !important; font-size: 0.99em !important;} /* sidebar */
66+
.sidebar-section-header-wrapper.sidebar-row {padding:4px !important;} /* sidebar headers bit to the left */
67+
.ember-view.sidebar-section-link.sidebar-row {height:25px !important;} /* sidebar row heights */
68+
.sidebar-section-link-prefix .svg-icon {height: 12px !important; width: 12px !important;} /* sidebar icons smaller */
69+
4470
`;
4571
document.head.appendChild(style);
4672
}
@@ -67,27 +93,88 @@ function AddAssetStoreLink()
6793

6894
function ShowOriginalPosterInfo()
6995
{
70-
// Select all <td> elements with the class 'posters topic-list-data'
71-
var posterCells = document.querySelectorAll('td.posters.topic-list-data');
72-
73-
// Loop through each <td> element
74-
posterCells.forEach(function(cell) {
75-
// Select the first <a> element with a data-user-card attribute inside the current <td>
76-
var firstUserLink = cell.querySelector('a[data-user-card]');
77-
78-
if (firstUserLink) {
79-
// Get the value of the data-user-card attribute
80-
var userCardValue = firstUserLink.getAttribute('data-user-card');
81-
82-
// Create a new <div> element to display the user card value
83-
var userCardDiv = document.createElement('div');
84-
userCardDiv.textContent = userCardValue;
85-
userCardDiv.style.fontSize = '12px'; // Optional: make the text smaller
86-
userCardDiv.style.marginTop = '4px'; // Optional: add some space above the text
87-
88-
// Insert the new <div> below the first image
89-
firstUserLink.parentNode.insertBefore(userCardDiv, firstUserLink.nextSibling);
96+
// Select all <td> elements with the class 'posters topic-list-data'
97+
var posterCells = document.querySelectorAll('td.posters.topic-list-data');
98+
99+
// Loop through each <td> element
100+
posterCells.forEach(function(cell)
101+
{
102+
// Select the first <a> element with a data-user-card attribute inside the current <td>
103+
var firstUserLink = cell.querySelector('a[data-user-card]');
104+
if (firstUserLink)
105+
{
106+
// Get the value of the data-user-card attribute
107+
var userCardValue = firstUserLink.getAttribute('data-user-card');
108+
109+
// Create a new <div> element to display the user card value
110+
var userCardDiv = document.createElement('div');
111+
userCardDiv.textContent = userCardValue;
112+
userCardDiv.style.fontSize = '12px'; // Optional: make the text smaller
113+
userCardDiv.style.marginTop = '4px'; // Optional: add some space above the text
114+
115+
// Insert the new <div> below the first image
116+
firstUserLink.parentNode.insertBefore(userCardDiv, firstUserLink.nextSibling);
117+
}
118+
});
119+
}
120+
121+
function FixPostActivityTime()
122+
{
123+
document.querySelectorAll('.relative-date').forEach(function(el) {
124+
const dataTime = parseInt(el.getAttribute('data-time'), 10);
125+
if (!dataTime) return;
126+
127+
const date = new Date(dataTime);
128+
const now = new Date();
129+
const diffInHours = Math.floor((now - date) / (1000 * 60 * 60));
130+
131+
let timeString;
132+
if (diffInHours > 6) {
133+
timeString = formatDateString(date);
134+
} else {
135+
const diffInMinutes = Math.floor((now - date) / (1000 * 60));
136+
timeString = `${diffInMinutes} minute${diffInMinutes !== 1 ? 's' : ''} ago`;
90137
}
138+
139+
el.textContent = timeString;
91140
});
92141
}
93142

143+
144+
145+
146+
function formatDate(date)
147+
{
148+
const options = { hour: '2-digit', minute: '2-digit', hour12: false };
149+
return date.toLocaleTimeString('en-GB', options); // Format as "HH:MM"
150+
}
151+
152+
function formatDateString(date)
153+
{
154+
const today = new Date();
155+
const yesterday = new Date(today);
156+
yesterday.setDate(today.getDate() - 1);
157+
const oneWeekAgo = new Date(today);
158+
oneWeekAgo.setDate(today.getDate() - 7);
159+
160+
if (date >= today.setHours(0, 0, 0, 0)) { // Today
161+
return `Today at ${formatDate(date)}`;
162+
} else if (date >= yesterday.setHours(0, 0, 0, 0)) { // Yesterday
163+
return `Yesterday at ${formatDate(date)}`;
164+
} else if (date >= oneWeekAgo) { // Within the past week
165+
const dayName = date.toLocaleDateString('en-GB', { weekday: 'long' });
166+
return `${dayName} at ${formatDate(date)}`;
167+
} else { // Older than one week
168+
return date.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' });
169+
}
170+
}
171+
172+
function NavBar()
173+
{
174+
// remove "try the" text
175+
document.querySelectorAll('div[title="Try the Product Areas"] .name').forEach(el => {
176+
if (el.textContent.trim() === "Try the Product Areas") {
177+
el.textContent = "Product Areas";
178+
}
179+
});
180+
}

0 commit comments

Comments
 (0)