chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames'], async function(result){
Settings = result.PolyPlus_Settings || {
PinnedGamesOn: true
}
if (Settings.PinnedGamesOn === true) {
const PlaceIDs = result.PolyPlus_PinnedGames || [];
const PinnedGamesContainer = document.createElement('div')
PinnedGamesContainer.innerHTML = `
Jump right back into your favorite games
Pinned Games
`
const RightSideColumn = document.getElementsByClassName('col-lg-8')[0];
if (document.getElementsByClassName('home-event-container')[0] === undefined) {
RightSideColumn.insertBefore(PinnedGamesContainer, RightSideColumn.children[0]);
} else {
RightSideColumn.insertBefore(PinnedGamesContainer, RightSideColumn.children[1]);
}
const PinnedGamesCard = document.getElementById('p+pinned_games_card')
for (let i = 0; i < PlaceIDs.length; i++) {
const PlaceID = PlaceIDs.toSorted((a, b) => b - a)[i]
const PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json())
const PlaceCard = document.createElement('a')
PlaceCard.classList = 'd-none'
PlaceCard.href = '/places/' + PlaceID
PlaceCard.innerHTML = `
`
if (!PlaceDetails.isActive) {
const PlayerCountText = PlaceCard.getElementsByClassName('p+pinned_games_playing')[0]
PlayerCountText.children[0].classList = 'text-warning fa-duotone fa-lock'
PlayerCountText.children[1].remove()
}
PinnedGamesCard.appendChild(PlaceCard)
}
PinnedGamesCard.children[0].remove()
PinnedGamesCard.classList.add('d-flex')
Array.from(PinnedGamesCard.children).forEach((place) => {place.classList.remove('d-none')})
}
if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
(async () => {
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
Utilities = Utilities.default;
const TrendingItems = document.getElementById('home-trendingItems');
for (let item of TrendingItems.children[1].getElementsByClassName('d-flex')[0].children) {
const Price = item.getElementsByClassName('text-success')[0];
if (Price !== undefined) {
const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrency.Currency);
let Span = document.createElement('span');
Span.classList = 'text-muted polyplus-price-tag';
Span.style = 'font-size: 0.7rem; font-weight: lighter;';
Span.innerText = '($' + IRLResult.result + ' ' + IRLResult.display + ')';
Price.appendChild(Span);
}
}
})();
}
if (Settings.HomeFriendCountOn === true) {
const FriendCount = (await (await fetch('https://polytoria.com/api/friends?page=1')).json()).meta.total;
const CountText = document.createElement('small');
CountText.classList = 'text-muted fw-lighter';
CountText.style.fontSize = '0.8rem';
CountText.innerText = ' (' + FriendCount + ')';
document.querySelector('#home-friendsOnline h5').appendChild(CountText);
}
})