let Username = window.location.pathname.split('/')[2]; const AvatarRow = document.getElementsByClassName('d-flex flex-row flex-nowrap overflow-x-scroll px-3 px-lg-0 mb-2 mb-lg-0')[0]; const AvatarHeading = document.querySelector('.section-title:has(i.fa-user-crown)'); var Settings; var BestFriends; let FavoriteBtn; let CalculateButton; let AvatarIFrame; let Utilities; if (Username) { (async () => { UserID = (await (await fetch('https://api.polytoria.com/v1/users/find?username=' + Username )).json()).id; Utilities = await import(chrome.runtime.getURL('resources/utils.js')); Utilities = Utilities.default; chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { Settings = result.PolyPlus_Settings || {}; const InfoColumns = document.getElementById('user-stats-card'); const UserIDRow = document.createElement('div') UserIDRow.classList = 'mb-1' UserIDRow.innerHTML = ` Player ID ${UserID} ` InfoColumns.children[0].insertBefore(UserIDRow, InfoColumns.children[0].children[1]); const CopyButton = UserIDRow.getElementsByTagName('a')[0] CopyButton.addEventListener('click', function(){ navigator.clipboard .writeText(UserID) .then(() => { CopyButton.classList.add('text-success') CopyButton.children[0].classList = 'fa-duotone fa-circle-check' CopyButton.children[0].style.marginLeft = '3px' setTimeout(() => { CopyButton.classList.remove('text-success') CopyButton.children[0].classList = 'fad fa-copy' CopyButton.children[0].style.marginLeft = '5px' }, 1500); }) }) if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) { IRLPrice(); } if (Settings.BestFriendsOn === true) { BestFriends(); } if (Settings.OutfitCostOn === true) { CalculateButton = document.createElement('small'); CalculateButton.classList = 'fw-normal text-success'; CalculateButton.style.letterSpacing = '0px'; CalculateButton.setAttribute('data-bs-toggle', 'tooltip'); CalculateButton.setAttribute('data-bs-title', "Calculate this avatar's cost!"); CalculateButton.setAttribute('data-bs-placement', 'right'); CalculateButton.innerHTML = ` $ calculate `; AvatarHeading.appendChild(CalculateButton); Utilities.InjectResource('registerTooltips'); let Calculating = false; CalculateButton.addEventListener('click', function () { if (Calculating === false) { Calculating = true; CalculateButton.innerText = '$ Calculating...'; OutfitCost(); } }); } /* */ AvatarIFrame = document.getElementById('user-avatar-card').getElementsByTagName('iframe')[0] if (Settings.AvatarDimensionToggleOn === true || 1 === 1) { const AvatarCard = document.getElementById('user-avatar-card') const ToggleButton = document.createElement('button') ToggleButton.classList = 'btn btn-primary btn-sm 3dviewtoggler isactive' ToggleButton.style = 'position: absolute; right: 15px; margin: 10px;' ToggleButton.innerHTML = '' AvatarCard.children[0].insertBefore(ToggleButton, AvatarIFrame) ToggleButton.addEventListener('click', async function(){ if (ToggleButton.children[0].classList.contains('fa-image')) { if (document.getElementById('polyplus-2davatar')) { AvatarIFrame.style.display = 'none' document.getElementById('polyplus-2davatar').style.display = 'block' ToggleButton.children[0].classList = 'toggleIcn fad fa-360-degrees' } else { const AvatarImage = document.createElement('img') AvatarImage.id = 'polyplus-2davatar' AvatarImage.width = AvatarIFrame.offsetWidth AvatarImage.height = AvatarIFrame.offsetHeight const UserDetails = (await (await fetch('https://api.polytoria.com/v1/users/' + UserID)).json()) AvatarImage.src = UserDetails.thumbnail.avatar AvatarIFrame.style.display = 'none' AvatarCard.children[0].insertBefore(AvatarImage, AvatarCard.getElementsByClassName('user-badges')[0]) ToggleButton.children[0].classList = 'toggleIcn fad fa-360-degrees' } } else { document.getElementById('polyplus-2davatar').style.display = 'none' AvatarIFrame.style.display = 'block' ToggleButton.children[0].classList = 'toggleIcn fad fa-image' } }) } }); })(); if (AvatarIFrame === null) { AvatarIFrame = document.getElementById('user-avatar-card').getElementsByTagName('iframe')[0] } const DropdownMenu = document.getElementsByClassName('dropdown-menu dropdown-menu-right')[0]; const CopyItem = document.createElement('a'); CopyItem.classList = 'dropdown-item text-primary'; CopyItem.href = '#'; CopyItem.innerHTML = ` Copy 3D Avatar URL `; DropdownMenu.appendChild(CopyItem); CopyItem.addEventListener('click', function () { navigator.clipboard .writeText(AvatarIFrame.src) .then(() => { alert('Successfully copied 3D avatar URL!'); }) .catch(() => { alert('Failure to copy 3D avatar URL.'); }); }); const ShareItem = document.createElement('a'); ShareItem.classList = 'dropdown-item text-warning'; ShareItem.href = '#'; ShareItem.innerHTML = ` Share your 3D Avatar URL! `; DropdownMenu.appendChild(ShareItem); ShareItem.addEventListener('click', function () { navigator.clipboard .writeText('Hey! Look at my Polytoria avatar in 3D [here](' + AvatarIFrame.src + ')!') .then(() => { alert('Successfully copied sharable 3D avatar URL!'); }) .catch(() => { alert('Failure to copy sharable 3D avatar URL.'); }); }); } else if (UserID && UserID[0] === '@') { const Username = window.location.pathname.split('/')[2].substring(1); let Reference = new URLSearchParams(new URL(window.location.href).search); if (!Reference.has('ref')) { Reference = ''; } fetch('https://api.polytoria.com/v1/users/find?username=' + Username) .then((response) => { if (!response.ok) { window.location.href = window.location.origin + decodeURIComponent(Reference.get('ref')); } else { return response.json(); } }) .then((data) => { window.location.href = 'https://polytoria.com/users/' + data.id; }) .catch((error) => { console.log('An error occurred:', error); }); } async function IRLPrice() { const NetWorthElement = document.getElementsByClassName('float-end text-success')[0]; const IRLResult = await Utilities.CalculateIRL(NetWorthElement.innerText, Settings.IRLPriceWithCurrency.Currency); NetWorthElement.innerHTML = NetWorthElement.innerHTML + '