From 6a42004dba7774f54097efc9da3c1aa9c6f3fda2 Mon Sep 17 00:00:00 2001 From: Index Date: Sat, 8 Jun 2024 21:21:33 -0500 Subject: [PATCH] disable best friends feature & improvements - disabled best friends feature - improved load asset by ID in avatar sandbox (originally was quickly added cause I was bored, now it actually works with different asset types and stuff) - add work in progress "automatic ad bidding" feature modal - fixed apply membership themes with nested setting objects - fixed try-on items feature defaulting to giving the preview avatar shirt and pants even if the user's avatar didn't have them - fixed "download place file" because site no longer uses csrf tokens --- js/account/avatar-sandbox2.js | 66 +++++++++++++++++++++++++------- js/account/home.js | 1 + js/account/profile.js | 6 +-- js/library-download.js | 31 ++++++++++++--- js/membership-themes.js | 47 +++++++++++++---------- js/places/place-edit.js | 7 ++-- js/store/item-view.js | 2 - manifest.json | 4 +- resources/avatar-sandbox.html | 10 +++++ settings.html | 71 +++++++++++++++++++++++++++++++++++ settings.js | 2 + 11 files changed, 198 insertions(+), 49 deletions(-) diff --git a/js/account/avatar-sandbox2.js b/js/account/avatar-sandbox2.js index a4b8be9..e71155a 100755 --- a/js/account/avatar-sandbox2.js +++ b/js/account/avatar-sandbox2.js @@ -174,10 +174,21 @@ if (new URLSearchParams(window.location.search).has('sandbox')) { }); let LoadAsset = document.getElementById('load-asset'); + const LoadAssetType = document.getElementById('load-asset-type') LoadAsset.addEventListener('click', async function () { - console.log('clickk'); - const MeshURL = (await (await fetch('https://api.polytoria.com/v1/assets/serve-mesh/' + LoadAsset.previousElementSibling.value)).json()).url; - Avatar.items.push(MeshURL); + if (!LoadAsset.previousElementSibling.value.startsWith('http') && !LoadAsset.previousElementSibling.value.startsWith('data:')) { + if (LoadAssetType.options[LoadAssetType.selectedIndex].value === 'hat') { + Avatar.items.push((await (await fetch('https://api.polytoria.com/v1/assets/serve-mesh/' + LoadAsset.previousElementSibling.value)).json()).url); + } else { + Avatar[LoadAssetType.options[LoadAssetType.selectedIndex].value] = (await (await fetch('https://api.polytoria.com/v1/assets/serve/' + LoadAsset.previousElementSibling.value + '/Asset')).json()).url; + } + } else { + if (LoadAssetType.options[LoadAssetType.selectedIndex].value === 'hat') { + Avatar.items.push(LoadAsset.previousElementSibling.value); + } else { + Avatar[LoadAssetType.options[LoadAssetType.selectedIndex].value] = LoadAsset.previousElementSibling.value + } + } UpdateAvatar(); }); }); @@ -190,7 +201,7 @@ if (new URLSearchParams(window.location.search).has('sandbox')) { } function UpdateAvatar() { - GenerateHash().then((hash) => { + FormatAvatar().then((hash) => { IFrame.addEventListener('load', function () { IFrame.src = 'https://polytoria.com/ptstatic/itemview/#' + hash; }); @@ -272,10 +283,19 @@ async function FormatAvatar() { // Hats, Tools: https://api.polytoria.com/v1/assets/serve-mesh/:id // or: https://api.polytoria.com/v1/assets/serve/:id/Asset + const meshPromises = Avatar.items.map(async (item, index) => { + if (typeof item === 'number') { + console.log(item); + FormattedAvatar.items[index] = await FetchMesh(item) + console.log('after url'); + //Avatar.items[index] = URL + } + }); + Avatar.items.forEach(async (item, index) => { if (typeof item === 'number') { console.log(item); - await FetchMesh(item) + FetchMesh(item) .then((URL) => { console.log('URL: ' + URL); FormattedAvatar.items[index] = URL; @@ -294,12 +314,10 @@ async function FormatAvatar() { } if (FormattedAvatar.face === undefined) { FormattedAvatar.face = 'https://c0.ptacdn.com/static/3dview/DefaultFace.png'; } - if (!FormattedAvatar.face.startsWith('data:') && !FormattedAvatar.face.startsWith('http')) { - if (FormattedAvatar.face && typeof FormattedAvatar.face === 'number') { - FormattedAvatar.face = await FetchAsset(FormattedAvatar.face); - } else { - FormattedAvatar.face = 'https://c0.ptacdn.com/static/3dview/DefaultFace.png'; - } + if (FormattedAvatar.face && typeof FormattedAvatar.face === 'number') { + FormattedAvatar.face = await FetchAsset(FormattedAvatar.face); + } else if (FormattedAvatar.face === undefined) { + FormattedAvatar.face = 'https://c0.ptacdn.com/static/3dview/DefaultFace.png'; } if (typeof FormattedAvatar.shirt === 'number') { @@ -308,9 +326,14 @@ async function FormatAvatar() { if (typeof FormattedAvatar.pants === 'number') { FormattedAvatar.pants = await FetchAsset(FormattedAvatar.pants); } + + await Promise.all(meshPromises) - console.log('Real Avatar: ', Avatar, 'Formatted: ', FormattedAvatar); - return FormattedAvatar; + console.log('Real Avatar: ', Avatar) + console.log('Formatted: ', FormattedAvatar) + console.log('URI: ', btoa(encodeURIComponent(JSON.stringify(FormattedAvatar)))) + console.log('Fix: ', JSON.stringify(decodeURIComponent(atob(btoa(encodeURIComponent(JSON.stringify(FormattedAvatar))))))); + return btoa(encodeURIComponent(JSON.stringify(FormattedAvatar))); } function LoadMyself() { @@ -399,6 +422,23 @@ async function FetchMesh(id) { return null; } console.log('https://api.polytoria.com/v1/assets/serve-mesh/:id'.replace(':id', id)); + + return new Promise((resolve, reject) => { + fetch('https://api.polytoria.com/v1/assets/serve-mesh/:id'.replace(':id', id)) + .then((response) => { + if (!response.ok) { + throw new Error('Network not ok'); + } + return response.json(); + }) + .then((data) => { + console.log(data, 'finished', data.url); + resolve(data.url); + }) + .catch((error) => { + console.log('Fetch error: ' + error); + }); + }) return fetch('https://api.polytoria.com/v1/assets/serve-mesh/:id'.replace(':id', id)) .then((response) => { if (!response.ok) { diff --git a/js/account/home.js b/js/account/home.js index 824b101..44a6644 100755 --- a/js/account/home.js +++ b/js/account/home.js @@ -152,6 +152,7 @@ function PinnedGames() { } function BestFriends() { + return Array.from(document.querySelectorAll('[bestFriend]')).forEach((element) => { element.removeAttribute('bestFriend'); element.getElementsByClassName('friend-name')[0].style.color = 'initial'; diff --git a/js/account/profile.js b/js/account/profile.js index 95b40fa..7eee982 100755 --- a/js/account/profile.js +++ b/js/account/profile.js @@ -1,4 +1,4 @@ -let UserID = window.location.pathname.split('/')[2]; +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)'); @@ -9,9 +9,9 @@ let CalculateButton; let Utilities; -if (UserID) { +if (Username) { (async () => { - UserID = (await (await fetch('https://api.polytoria.com/v1/users/')).json()).id; + 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; diff --git a/js/library-download.js b/js/library-download.js index 797bb18..432e761 100644 --- a/js/library-download.js +++ b/js/library-download.js @@ -1,9 +1,9 @@ const AssetID = window.location.pathname.split('/')[2]; const LibraryType = document.querySelectorAll('ol a')[1].innerText.toLowerCase(); -const LibraryTypes = ['model', 'audio', 'decal', 'mesh']; +const LibraryTypes = ['model', 'audio', 'decal', 'mesh', 'shirt', 'pant']; if (LibraryTypes.filter((x) => !LibraryTypes.some(element => element.startsWith(LibraryType))).length > 0) { - chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { + chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) { Settings = result.PolyPlus_Settings || {}; if (Settings.LibraryDownloadsOn === false) { @@ -18,6 +18,7 @@ if (LibraryTypes.filter((x) => !LibraryTypes.some(element => element.startsWith( DownloadLink.innerHTML = ` Download`; Dropdown.insertBefore(DownloadLink, Dropdown.children[Dropdown.children.length - 1]); + console.log('type', LibraryType, LibraryType.startsWith('shirt'), LibraryType.startsWith('pant')) switch (LibraryType) { case LibraryType.startsWith('model'): DownloadLink.href = 'https://api.polytoria.com/v1/models/get-model?id=' + AssetID; @@ -26,21 +27,39 @@ if (LibraryTypes.filter((x) => !LibraryTypes.some(element => element.startsWith( const AudioBlob = new Blob([document.getElementsByTagName('audio')[0]], {type: 'octet-steam'}); DownloadLink.href = URL.createObjectURL(AudioBlob); DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.mp3'; - case LibraryType.startsWith('decal'): + case (LibraryType.startsWith('decal')): const DecalBlob = new Blob([document.getElementsByClassName('store-thumbnail')[0]], {type: 'image/png'}); DownloadLink.href = URL.createObjectURL(DecalBlob); DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.png'; break; } - if (LibraryType.startsWith('mesh')) { + if (LibraryType.startsWith('shirt') || LibraryType.startsWith('pant')) { + let ClothingURL = null; + DownloadLink.addEventListener('click', async function () { + if (ClothingURL !== null) { + return; + } + ClothingURL = (await (await fetch('https://api.polytoria.com/v1/assets/serve/' + AssetID + '/Asset')).json()); + + if (ClothingURL.success === true) { + //const ClothingBlob = new Blob([(await (await fetch(ClothingURL.url)).blob())], {type: 'image/png'}) + const ClothingBlob = (await (await fetch(ClothingURL.url)).blob()) + DownloadLink.href = URL.createObjectURL(ClothingBlob); + DownloadLink.download = document.getElementsByTagName('h1')[0].innerText + '.png'; + + DownloadLink.click(); + } else { + alert('Failure to fetch .png file for clothing item'); + } + }); + } else if (LibraryType.startsWith('mesh')) { let MeshURL = null; DownloadLink.addEventListener('click', async function () { if (MeshURL !== null) { return; } - MeshURL = await fetch('https://api.polytoria.com/v1/assets/serve-mesh/' + AssetID); - MeshURL = await MeshURL.json(); + MeshURL = (await (await fetch('https://api.polytoria.com/v1/assets/serve-mesh/' + AssetID)).json()); if (MeshURL.success === true) { DownloadLink.href = MeshURL.url; diff --git a/js/membership-themes.js b/js/membership-themes.js index 36b4208..fa17322 100755 --- a/js/membership-themes.js +++ b/js/membership-themes.js @@ -1,13 +1,17 @@ chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { Settings = result.PolyPlus_Settings || { + ApplyMembershipTheme: { + Enabled: false, + Theme: 0 + }, ApplyMembershipThemeOn: false, ApplyMembershipThemeTheme: 0 }; - if (Settings.ApplyMembershipThemeOn !== true) { + if (Settings.ApplyMembershipTheme.Enabled !== true) { return; } - MembershipTheme = Settings.ApplyMembershipThemeTheme === 0 ? 'plus' : 'plusdx'; + MembershipTheme = Settings.ApplyMembershipTheme.Theme === 0 ? 'plus' : 'plusdx'; document.addEventListener('DOMContentLoaded', function () { if (document.getElementsByClassName('card-header')[0] && document.getElementsByClassName('card-header')[0].innerText === ' Page not found') { @@ -24,25 +28,28 @@ chrome.storage.sync.get(['PolyPlus_Settings'], function (result) { Navbar.classList.add('navbar-' + MembershipTheme); Sidebar.classList.add('sidebar-' + MembershipTheme); - if (MembershipTheme === 'plusdx') { - let SidebarLogo = document.querySelector('.nav-sidebar img'); - SidebarLogo.setAttribute('src', 'https://c0.ptacdn.com/static/images/branding/icon-plusdx.bd9daa92.svg'); - let SidebarLogoLabel = document.createElement('div'); - SidebarLogoLabel.classList = 'nplusdx-banner'; - SidebarLogoLabel.innerHTML = ` - - `; - SidebarLogo.parentElement.appendChild(SidebarLogoLabel); + let SidebarLogo = Sidebar.getElementsByTagName('img')[0]; + if (MembershipTheme === 'plus') { + SidebarLogo.src = 'https://c0.ptacdn.com/static/images/branding/icon-plus.8f6e41f1.svg' + } else { + SidebarLogo.src = 'https://c0.ptacdn.com/static/images/branding/icon-plusdx.bd9daa92.svg' + } - if (window.location.pathname === '/home') { - let HomeUsernameText = document.getElementsByClassName('home-title2')[0]; - HomeUsernameText.children[0].classList.add('text-plusdx'); - let Label = document.createElement('div'); - Label.classList = 'hplusdx-banner rounded-2'; - Label.setAttribute('style', 'margin-top: -8px; animation-delay: 0.09s;'); - Label.innerText = 'Deluxe'; - HomeUsernameText.appendChild(Label); - } + let SidebarLogoLabel = document.createElement('div'); + SidebarLogoLabel.classList = 'n' + MembershipTheme + '-banner'; + SidebarLogoLabel.innerHTML = ` + + `; + SidebarLogo.parentElement.appendChild(SidebarLogoLabel); + + if (MembershipTheme === 'plusdx' && window.location.pathname === '/home') { + let HomeUsernameText = document.getElementsByClassName('home-title2')[0]; + HomeUsernameText.classList.add('text-plusdx'); + let Label = document.createElement('div'); + Label.classList = 'hplusdx-banner reqFadeAnim rounded-2'; + Label.setAttribute('style', 'margin-top:-8px'); + Label.innerText = 'Deluxe'; + HomeUsernameText.parentElement.appendChild(Label); } }); }); diff --git a/js/places/place-edit.js b/js/places/place-edit.js index 92904a5..cc3b323 100755 --- a/js/places/place-edit.js +++ b/js/places/place-edit.js @@ -95,13 +95,12 @@ function RequestGameProfile() { async function CopyOwnedPlace() { console.log('ran function'); if (PlaceData === null) { - PlaceData = await fetch('https://api.polytoria.com/v1/places/' + 2640); + PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID); PlaceData = await PlaceData.json(); } if (PlaceData.creator.id !== parseInt(JSON.parse(window.localStorage.getItem('p+account_info')).ID)) { - console.log('returned'); - //return + return } const DIV = document.createElement('div'); @@ -123,9 +122,11 @@ async function CopyOwnedPlace() { let CreatorToken = await fetch('https://polytoria.com/api/places/edit', { method: 'POST', + /* headers: { 'X-CSRF-Token': document.querySelector('input[name="_csrf"]').value }, + */ body: JSON.stringify({placeID: PlaceID}) }); CreatorToken = await CreatorToken.json(); diff --git a/js/store/item-view.js b/js/store/item-view.js index 7953ac6..9b9aa02 100755 --- a/js/store/item-view.js +++ b/js/store/item-view.js @@ -175,8 +175,6 @@ function TryOnItems() { const Avatar = { useCharacter: true, items: [], - shirt: 'https://c0.ptacdn.com/assets/uWrrnFGwgNN5W171vqYTWY7E639rKiXK.png', - pants: 'https://c0.ptacdn.com/assets/HD6TFdXD8CaflRNmd84VCNyNsmTB0SH3.png', headColor: '#e0e0e0', torsoColor: '#e0e0e0', leftArmColor: '#e0e0e0', diff --git a/manifest.json b/manifest.json index 3d9b622..8e25820 100755 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "manifest_version": 3, "author": "Index", "name": "Poly+", - "version": "1.11", - "version_name": "Pre-Release Build (v1.1.1)", + "version": "1.21", + "version_name": "Pre-Release Build (v1.2.1)", "description": "Power-up your Polytoria experience with Poly+! Created by Index.", "homepage_url": "https://polyplus.vercel.app/", "permissions": ["storage", "contextMenus", "scripting", "alarms", "notifications"], diff --git a/resources/avatar-sandbox.html b/resources/avatar-sandbox.html index eec66b3..90eacd6 100755 --- a/resources/avatar-sandbox.html +++ b/resources/avatar-sandbox.html @@ -64,10 +64,20 @@ +
+
+
diff --git a/settings.html b/settings.html index cedda11..058cc66 100755 --- a/settings.html +++ b/settings.html @@ -321,6 +321,63 @@
+ + + +

Poly+ Settings

@@ -343,6 +400,7 @@
* Forum Mentions do not notify the user or show up as a notification on their account.

+

  @@ -607,6 +666,18 @@

+

EXPERIMENTAL SETTINGS

diff --git a/settings.js b/settings.js index 4110b51..d8b6f42 100644 --- a/settings.js +++ b/settings.js @@ -194,10 +194,12 @@ function SetSetting(element, value, update, modalParent) { return "Are you sure you'd like to leave? Your Poly+ settings haven't been saved." }; } + /* if (AreIdentical(Settings, RecentSave) === true) { document.title = 'Poly+ Settings' SaveBtn.disabled = true } + */ } function GetSettingValue(element, modalParent) {