Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/Assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,10 @@
"playerCountUnknownTooltip": "Player count is unknown, this is a Roblox limitation. The thumbnails are not representative of the people in game.",
"playerCountUnknownLabel": "Player count unknown"
},
"rejoinServer": {
"tooltip": "Rejoin previous server",
"closed": "Your previous server is no longer available."
},
"recentServers": {
"title": "Recent Servers",
"refresh": "Refresh",
Expand Down
11 changes: 11 additions & 0 deletions src/content/core/settings/settingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,17 @@ export const SETTINGS_CONFIG = {
type: 'checkbox',
default: true,
storageKey: 'rovalra_server_history',
childSettings: {
rejoinServerButtonEnabled: {
label: 'Rejoin Previous Server Button',
description: [
'Adds a button next to the Play button that joins the last server you were in for that experience.',
],
type: 'checkbox',
default: true,
contributors: ['4975603156'],
},
},
},
TotalServersEnabled: {
label: 'Total Servers',
Expand Down
124 changes: 124 additions & 0 deletions src/content/features/games/rejoinServerButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { observeElement, observeResize } from '../../core/observer.js';
import { getPlaceIdFromUrl } from '../../core/idExtractor.js';
import { settings } from '../../core/settings/getSettings.js';
import { launchGame } from '../../core/utils/launcher.js';
import { addTooltip } from '../../core/ui/tooltip.js';
import { showSystemAlert } from '../../core/ui/roblox/alert.js';
import { ts } from '../../core/locale/i18n.js';
import { checkServerIsActive } from './serverlist/recentservers.js';

const CONTAINER_SELECTOR = '#game-details-play-button-container';
const PLAY_BUTTON_SELECTOR = 'button[data-testid="play-button"]';
const BUTTON_ID = 'rovalra-rejoin-server-button';
const ICON_PATH =
'M13 3a9 9 0 0 0-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42A8.954 8.954 0 0 0 13 21a9 9 0 0 0 0-18m-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8z';

let listening = false;
let processing = false;

async function getLastServer(placeId) {
const { rovalra_server_history: history = {} } =
await chrome.storage.local.get({ rovalra_server_history: {} });
return history[placeId]?.[0]?.presence || null;
}

function createIcon() {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', '26');
svg.setAttribute('height', '26');
svg.setAttribute('viewBox', '0 0 24 24');
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute('d', ICON_PATH);
svg.append(path);
return svg;
}

async function rejoin(button, placeId) {
if (button.disabled) return;
button.disabled = true;
try {
const server = await getLastServer(placeId);
if (
!server?.gameId ||
!(await checkServerIsActive(placeId, server.gameId))
) {
showSystemAlert(ts('rejoinServer.closed'), 'warning');
return;
}
launchGame(server.rootPlaceId || placeId, server.gameId);
} finally {
button.disabled = false;
}
}

async function processContainer(container) {
const placeId = getPlaceIdFromUrl();
if (!placeId || !container.querySelector(PLAY_BUTTON_SELECTOR)) return;
if (processing) return;

processing = true;
try {
await renderButton(container, placeId);
} finally {
processing = false;
}
}

async function renderButton(container, placeId) {
const server = await getLastServer(placeId);
const existing = document.getElementById(BUTTON_ID);
if (!server?.gameId) {
existing?.remove();
return;
}
if (existing) return;

const button = document.createElement('button');
button.type = 'button';
button.id = BUTTON_ID;
button.className = 'btn-primary-md rovalra-rejoin-server-button';
button.setAttribute('aria-label', ts('rejoinServer.tooltip'));
button.append(createIcon());
button.addEventListener('click', (event) => {
event.stopPropagation();
rejoin(button, placeId);
});

container.append(button);
const playButton = container.querySelector(PLAY_BUTTON_SELECTOR);
const syncSize = () => {
const { height } = playButton.getBoundingClientRect();
if (height > 0)
button.style.width = button.style.height = `${height}px`;
};
syncSize();
observeResize(playButton, syncSize);
addTooltip(button, ts('rejoinServer.tooltip'), { position: 'top' });
}

export async function init() {
if (
!(await settings.recentServersEnabled) ||
(await settings.rejoinServerButtonEnabled) === false
) {
return;
}

observeElement(CONTAINER_SELECTOR, processContainer);
observeElement(
`${CONTAINER_SELECTOR} button`,
(button) => {
const container = button.closest(CONTAINER_SELECTOR);
if (container) processContainer(container);
},
{ multiple: true },
);

if (listening) return;
listening = true;
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace !== 'local' || !changes.rovalra_server_history) return;
const container = document.querySelector(CONTAINER_SELECTOR);
if (container) processContainer(container);
});
}
2 changes: 1 addition & 1 deletion src/content/features/games/serverlist/recentservers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
return serverItem;
}

function createModernServerItem(serverData, userThumbnailUrl, userId) {

Check warning on line 88 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

'userId' is defined but never used
const { presence, timestamp } = serverData;
const serverItem = document.createElement('div');
serverItem.className =
Expand All @@ -112,7 +112,7 @@
${avatarHtml}
<div class="flex flex-col min-width-0">
<span class="text-body-large content-emphasis text-truncate-end">${ts('recentServers.meAlt')}</span>
<span class="text-body-medium content-muted">${subtitle}</span>

Check warning on line 115 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ CSS variable '--color-state-press' is not defined in sitewide.scss

Check warning on line 115 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ CSS variable '--color-state-hover' is not defined in sitewide.scss
</div>
</div>
<div class="flex flex-col items-center gap-xsmall grow-0 shrink-0 basis-auto">
Expand All @@ -120,7 +120,7 @@
<button type="button" class="foundation-web-button relative clip group/interactable focus-visible:outline-focus disabled:outline-none cursor-pointer relative flex items-center justify-center stroke-none padding-y-none select-none radius-medium text-label-small height-800 padding-x-small bg-action-standard content-action-standard width-full rovalra-join-btn">
<div role="presentation" class="absolute inset-[0] transition-colors group-hover/interactable:bg-[var(--color-state-hover)] group-active/interactable:bg-[var(--color-state-press)] group-disabled/interactable:bg-none"></div>
<span class="flex items-center min-width-0 gap-xsmall">
<span class="padding-y-xsmall text-truncate-end text-no-wrap">${ts('serverList.join')}</span>

Check warning on line 123 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ CSS variable '--color-state-press' is not defined in sitewide.scss

Check warning on line 123 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ CSS variable '--color-state-hover' is not defined in sitewide.scss
</span>
</button>
</div>
Expand Down Expand Up @@ -159,7 +159,7 @@
return serverItem;
}

async function checkServerIsActive(placeId, gameId) {
export async function checkServerIsActive(placeId, gameId) {
try {
const info = await callRobloxApiJson({
subdomain: 'gamejoin',
Expand All @@ -182,7 +182,7 @@
}

return false;
} catch (error) {

Check warning on line 185 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

'error' is defined but never used
return false;
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@
separator.className =
'margin-y-large rovalra-modern-separator';
separator.innerHTML =
'<div role="separator" data-orientation="horizontal" aria-orientation="horizontal" class="stroke-default self-stretch" style="border-right-width: 0px; border-bottom-width: 0px; box-sizing: border-box; border-style: solid; height: 0px; border-top-width: var(--stroke-standard); border-left-width: 0px;"></div>';

Check warning on line 301 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ CSS variable '--stroke-standard' is not defined in sitewide.scss
}

const modernSections = Array.from(
Expand Down Expand Up @@ -430,7 +430,7 @@
.forEach((el) => el.remove());

const spinnerSection = document.createElement('div');
spinnerSection.style.cssText =

Check failure on line 433 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Avoid writing raw CSS in JavaScript. Please define styles in 'src/css/' (SCSS) and use class names instead to promote reuse and maintainability
'width: 100%; display: flex; justify-content: center; padding: 20px;';
spinnerSection.innerHTML =
'<span class="spinner spinner-default"></span>';
Expand Down Expand Up @@ -481,7 +481,7 @@
const noServers = document.createElement('div');
noServers.className =
'section-content-off empty-game-instances-container';
noServers.innerHTML = `<p class="no-servers-message">${await t('recentServers.noneFound')}</p>`;

Check failure on line 484 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Unsafe innerHTML assignment detected. You must wrap the value with DOMPurify.sanitize() or use the safeHtml helper
gridContainer.appendChild(noServers);
return;
}
Expand All @@ -501,7 +501,7 @@
const noActive = document.createElement('div');
noActive.className =
'section-content-off empty-game-instances-container';
noActive.innerHTML = `<p class="no-servers-message">${await t('recentServers.noActiveFound')}</p>`;

Check failure on line 504 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Unsafe innerHTML assignment detected. You must wrap the value with DOMPurify.sanitize() or use the safeHtml helper
gridContainer.appendChild(noActive);
return;
}
Expand Down Expand Up @@ -566,7 +566,7 @@
const noActive = document.createElement('div');
noActive.className =
'section-content-off empty-game-instances-container';
noActive.innerHTML = `<p class="no-servers-message">${ts('recentServers.noActiveFound')}</p>`;

Check failure on line 569 in src/content/features/games/serverlist/recentservers.js

View workflow job for this annotation

GitHub Actions / eslint

⚠️ Unsafe innerHTML assignment detected. You must wrap the value with DOMPurify.sanitize() or use the safeHtml helper
gridContainer.appendChild(noActive);
}
if (obsReq) obsReq.active = false;
Expand Down
2 changes: 2 additions & 0 deletions src/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import { init as initFreeBadgeQuota } from './features/games/freeBadgeQuota.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';
import { init as initRejoinServerButton } from './features/games/rejoinServerButton.js';
import { init as initSubplaces } from './features/games/tab/Subplaces.js';
import { initServerIdExtraction } from './core/games/servers/serverids.js';
import { init as initGameTrailers } from './features/games/thumbnails/gametrailers.js';
Expand Down Expand Up @@ -419,6 +420,7 @@ const featureRoutes = [
initBotDetector,
initServerList,
initRegionPlayButton,
initRejoinServerButton,
bannertest,
initGameTrailers,
quickOutfits,
Expand Down
23 changes: 23 additions & 0 deletions src/css/features/games/rejoin_server_button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.rovalra-rejoin-server-button {
display: flex !important;
align-items: center;
justify-content: center;
flex-shrink: 0;
margin-left: 5px !important;
padding: 0 !important;
border: none !important;
border-radius: 12px;
background-color: var(--rovalra-playbutton-color) !important;
color: white !important;
cursor: pointer;
order: 6 !important;

svg path {
fill: white;
}

&:disabled {
opacity: 0.6;
cursor: default;
}
}
1 change: 1 addition & 0 deletions src/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@
@use 'features/avatar/game_outfits.scss';
@use 'components/dropdown.scss';
@use 'components/user_card_tooltip.scss';
@use 'features/games/rejoin_server_button.scss';
Loading