This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/forum/forum-view.js
Index 46efc889e7 Items in Wishlist get Removed upon Purchase
- Items that are in your "Item Wishlist" will now be automatically removed when purchased. You can now also no longer add items to your "Item Wishlist" if you already own the item.

- Fixed issue with forgetting to remove simplified-profile.js from manifest.json after deleting the file

- Added all experimental settings to the settings page ("Game Profiles", "Inline Editing", "Forum Unix Timestamps")

- Removed commented out settings on the settings page

- Removed the "Handle" part of all function names (eg. "HandlePinnedGames()" -> "PinnedGames()")

- Moved profile/profile.js to account/profile.js

- You can now quickly copy a message to share your or somebody else's 3D avatar URL on profile pages.
2024-02-11 11:30:59 -06:00

51 lines
No EOL
2.1 KiB
JavaScript

const ForumText = document.querySelectorAll('p:not(.text-muted):not(.mb-0)')
var Settings = []
chrome.storage.sync.get(['PolyPlus_Settings'], function(result) {
Settings = result.PolyPlus_Settings || {
ForumMentsOn: false,
ForumUnixStampsOn: false
}
if (Settings.ForumMentsOn === true) {
ForumMentions()
}
if (Settings.ForumUnixStampsOn === true) {
ForumUnixTimestamps()
}
});
function ForumMentions() {
const Regex = /@([\w.]+)/g
for (let text of ForumText) {
let FormattedText = text.innerHTML
let match;
while ((match = Regex.exec(text.innerText)) !== null) {
const Username = match[0].substring(1)
FormattedText = FormattedText.replaceAll(match[0], `<a href="/profile/${Username}?ref=${encodeURIComponent(window.location.pathname)}" class="polyplus-mention">${match[0]}</a>`)
}
text.innerHTML = FormattedText
}
}
function ForumUnixTimestamps() {
const Regex = /&lt;t:[A-Za-z0-9]+&gt;/i
for (let text of ForumText) {
let FormattedText = text.innerHTML
let match;
while ((match = Regex.exec(FormattedText)) !== null) {
const Timestamp = new Date(match[0].substring(6, match[0].length - 4) * 1000)
const Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
const Distance = new Intl.RelativeTimeFormat({numeric: 'auto', style: 'short'}).format(Math.floor((Timestamp - new Date()) / (60 * 1000)), 'day')
const Result = `<code style="color: orange;">${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()} (${["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][Timestamp.getDay()-1]}) at ${Timestamp.getHours()-12}:${String(Timestamp.getMinutes()).padStart(2, "0")} (${Distance})</code>`
FormattedText = FormattedText.replaceAll(match[0], Result)
console.log(FormattedText)
}
text.innerHTML = FormattedText
}
}