diff --git a/.github/workflows/prs.yml b/.github/workflows/prs.yml index ba8208588..6753605b8 100644 --- a/.github/workflows/prs.yml +++ b/.github/workflows/prs.yml @@ -79,6 +79,8 @@ jobs: for f in ${{ steps.changed.outputs.all_changed_files }}; do while read host; do [ -z "$host" ] && continue + # The game analytics button opens the game page on Rolimons in a new tab. + [ "$host" = "www.rolimons.com" ] && continue if ! echo "$host" | grep -qE '(^|\.)(rovalra|roblox|rbxcdn|eslint|feross|github|opencollective|paulmillr|polar|registry\.npmjs|tidelift|i18next|locize|patreon)\.(com|org|sh)$'; then echo "::error file=$f::Disallowed link host: $host" BAD=1 diff --git a/public/Assets/locales/en.json b/public/Assets/locales/en.json index 5c7a85251..6b21c323c 100644 --- a/public/Assets/locales/en.json +++ b/public/Assets/locales/en.json @@ -372,6 +372,10 @@ "games": { "failedToLoad": "Failed to load game" }, + "rolimonsGameLink": { + "label": "Rolimons", + "tooltip": "View this game's analytics on Rolimons." + }, "gameBookmarks": { "bookmark": "Bookmark", "saved": "Bookmarked", diff --git a/src/content/core/configs/userIds.js b/src/content/core/configs/userIds.js index f37730777..8f5d771f3 100644 --- a/src/content/core/configs/userIds.js +++ b/src/content/core/configs/userIds.js @@ -46,6 +46,7 @@ export const CONTRIBUTOR_USER_IDS = [ '3774777796', // hhhhhhhf334 '1388867949', '4975603156', // KyoMarketing + '1718514709', // BagischandraK '112558831', ]; diff --git a/src/content/features/games/rolimonsGameLink.js b/src/content/features/games/rolimonsGameLink.js new file mode 100644 index 000000000..91c49f299 --- /dev/null +++ b/src/content/features/games/rolimonsGameLink.js @@ -0,0 +1,55 @@ +import { getAssets } from '../../core/assets.js'; +import { getPlaceIdFromUrl } from '../../core/idExtractor.js'; +import { observeElement } from '../../core/observer.js'; +import { t } from '../../core/locale/i18n.js'; +import { addTooltip } from '../../core/ui/tooltip.js'; +import { createButton } from '../../core/ui/buttons.js'; + +const STATS_SELECTOR = '#game-details-about-tab-container .game-stat-container'; +const LINK_CONTAINER_CLASS = 'rovalra-rolimons-game-link-container'; + +function addRolimonsLink(statsContainer, labelText, tooltipText) { + if ( + statsContainer.dataset.rovalraRolimonsLink === 'true' || + !statsContainer.isConnected + ) { + return; + } + + const placeId = getPlaceIdFromUrl(); + if (!/^\d+$/.test(placeId || '')) return; + + statsContainer.dataset.rovalraRolimonsLink = 'true'; + + const rolimonsUrl = `https://www.rolimons.com/game/${placeId}`; + const button = createButton(labelText, 'secondary', { + classList: ['rovalra-rolimons-game-link'], + onClick: () => window.open(rolimonsUrl, '_blank', 'noopener,noreferrer'), + }); + button.type = 'button'; + + const icon = document.createElement('img'); + icon.src = getAssets().rolimonsIcon; + icon.alt = ''; + icon.setAttribute('aria-hidden', 'true'); + button.prepend(icon); + + addTooltip(button, tooltipText, { position: 'top' }); + + const linkContainer = document.createElement('li'); + linkContainer.className = LINK_CONTAINER_CLASS; + linkContainer.appendChild(button); + statsContainer.appendChild(linkContainer); +} + +export async function init() { + const [label, tooltip] = await Promise.all([ + t('rolimonsGameLink.label'), + t('rolimonsGameLink.tooltip'), + ]); + observeElement( + STATS_SELECTOR, + (statsContainer) => addRolimonsLink(statsContainer, label, tooltip), + { multiple: true }, + ); +} diff --git a/src/content/index.js b/src/content/index.js index ddcf6b4a3..c1adf970d 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -115,6 +115,7 @@ import { init as initBadgeEarnedDate } from './features/games/badgeEarnedDate.js import { init as initBadgeSort } from './features/games/badgeSort.js'; import { init as initGameStatTimestamps } from './features/games/gameStatTimestamps.js'; import { init as initFreeBadgeQuota } from './features/games/freeBadgeQuota.js'; +import { init as initRolimonsGameLink } from './features/games/rolimonsGameLink.js'; import { init as initServerList } from './features/games/serverlist/serverlist.js'; import { initRecentServers } from './features/games/serverlist/recentservers.js'; import { init as initRegionPlayButton } from './features/games/RegionPlayButton.js'; @@ -434,6 +435,7 @@ const featureRoutes = [ initCatalogExplorer, initUnderReviewPill, initGameStatTimestamps, + initRolimonsGameLink, ], }, // private games and game pages diff --git a/src/css/features/games/rolimonsGameLink.scss b/src/css/features/games/rolimonsGameLink.scss new file mode 100644 index 000000000..32297a113 --- /dev/null +++ b/src/css/features/games/rolimonsGameLink.scss @@ -0,0 +1,37 @@ +#game-details-about-tab-container + ul.game-stat-container[data-rovalra-rolimons-link='true'] { + display: flex; + flex-wrap: wrap; + height: auto; +} + +#game-details-about-tab-container li.rovalra-rolimons-game-link-container { + display: flex; + align-items: center; + justify-content: center; + flex: 0 0 100%; + width: 100%; + box-sizing: border-box; + margin: 8px 0 0; +} + +#game-details-about-tab-container button.rovalra-rolimons-game-link { + display: inline-flex; + flex-direction: row; + align-items: center; + justify-content: center; + gap: 8px; + min-width: 120px; + height: 40px; + padding: 0 12px; + box-sizing: border-box; + white-space: nowrap; + + img { + display: block; + width: 14px; + height: 19px; + object-fit: contain; + filter: grayscale(1) brightness(0) invert(0.82); + } +} diff --git a/src/css/main.scss b/src/css/main.scss index 0b16a8f88..82168a942 100644 --- a/src/css/main.scss +++ b/src/css/main.scss @@ -45,6 +45,7 @@ @use 'features/games/gameBookmarks.scss'; @use 'features/games/events.scss'; @use 'features/games/hiddenBadges.scss'; +@use 'features/games/rolimonsGameLink.scss'; @use 'features/games/badgeLayoutToggle.scss'; @use 'features/games/badgeSort.scss'; @use 'features/groups/antibots.scss';