From fc230ec3b8edb94cfdd8aa28edc35b238a543e02 Mon Sep 17 00:00:00 2001 From: Index Date: Mon, 27 May 2024 17:01:25 -0500 Subject: [PATCH] rewrote settings and new features - rewrote settings - reorganized several settings as nested objects - added avatars enabled sub-setting of collectibles hoarder list - added default min copies - new feature: "Timed-Item Owner Check" - new feature: "Hide User Ads" --- js/account/avatar-sandbox2.js | 10 +- js/account/home.js | 8 +- js/account/inventory.js | 4 +- js/account/profile.js | 10 +- js/account/transactions.js | 2 +- js/debug.js | 414 ++++++++++++++++----------------- js/everywhere.js | 82 ++++--- js/guilds.js | 6 +- js/op-comments.js | 1 - js/places/place-edit.js | 6 +- js/places/place-view.js | 6 +- js/store/item-view.js | 264 +++++++++++++++------ js/store/store.js | 13 +- manifest.json | 11 +- resources/avatar-sandbox.html | 10 +- resources/getUserDetails.js | 4 + resources/utils.js | 38 +++- settings.html | 72 ++++-- settings.js | 14 +- settings2.js | 417 ++++++++++++++++++++++++++++++++++ 20 files changed, 1023 insertions(+), 369 deletions(-) create mode 100644 resources/getUserDetails.js create mode 100644 settings2.js diff --git a/js/account/avatar-sandbox2.js b/js/account/avatar-sandbox2.js index 60cca8a..d145955 100755 --- a/js/account/avatar-sandbox2.js +++ b/js/account/avatar-sandbox2.js @@ -1,4 +1,4 @@ -const UserID = JSON.parse(window.localStorage.getItem('account_info')).ID +const UserID = JSON.parse(window.localStorage.getItem('p+account_info')).ID const BodyColors = [ "#f8f8f8", "#cdcdcd", @@ -174,6 +174,14 @@ if (new URLSearchParams(window.location.search).has('sandbox')) { OpenInNewTab.addEventListener('click', function(){ UpdateAvatar() }); + + let LoadAsset = document.getElementById('load-asset') + 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) + UpdateAvatar() + }) }); } else { const SandboxButton = document.createElement('a') diff --git a/js/account/home.js b/js/account/home.js index b60b5d4..8f5467f 100755 --- a/js/account/home.js +++ b/js/account/home.js @@ -9,13 +9,13 @@ var BestFriendsData let Utilities; chrome.storage.sync.get(['PolyPlus_Settings'], async function(result) { - Settings = result.PolyPlus_Settings || {} + Settings = result.PolyPlus_Settings || Utilities.DefaultSettings - if (Settings.IRLPriceWithCurrencyOn === true) { + if (Settings.IRLPriceWithCurrency.Enabled === true) { IRLPrice() } - if (Settings.ShowFriendCount === true) { + if (Settings.HomeFriendCountOn === true) { ShowFriendCount() } @@ -183,7 +183,7 @@ async function IRLPrice() { 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.IRLPriceWithCurrencyCurrency) + const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrency.Currency) let Span = document.createElement('span') Span.classList = 'text-muted polyplus-price-tag' diff --git a/js/account/inventory.js b/js/account/inventory.js index 51be6ca..58bf9a8 100755 --- a/js/account/inventory.js +++ b/js/account/inventory.js @@ -1,6 +1,6 @@ if (window.location.pathname.split('/')[3] === "inventory") { const UserID = window.location.pathname.split('/')[2] - if (UserID === JSON.parse(window.localStorage.getItem('account_info')).ID) { + if (UserID === JSON.parse(window.localStorage.getItem('p+account_info')).ID) { let Nav = document.getElementsByClassName('nav-pills')[0] let WishlistNav = document.createElement('li') WishlistNav.classList.add('nav-item') @@ -155,7 +155,7 @@ if (window.location.pathname.split('/')[3] === "inventory") { function Update(type, query, isLimited, isAvailable) { let ItemGrid = document.getElementsByClassName('itemgrid')[0] - let BrickBalance = parseInt(JSON.parse(window.localStorage.getItem('account_info')).Bricks) + let BrickBalance = parseInt(JSON.parse(window.localStorage.getItem('p+account_info')).Bricks) query = query.toLowerCase(); let Results = Array.from(ItemGrid.children) for (let i = 0; i < Results.length; i++) { diff --git a/js/account/profile.js b/js/account/profile.js index d2ffc39..f7201cd 100755 --- a/js/account/profile.js +++ b/js/account/profile.js @@ -18,7 +18,7 @@ if (UserID) { chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { Settings = result.PolyPlus_Settings || {} - if (Settings.IRLPriceWithCurrencyOn === true) { + if (Settings.IRLPriceWithCurrency.Enabled === true) { IRLPrice() } @@ -118,8 +118,8 @@ if (UserID) { async function IRLPrice() { const NetWorthElement = document.getElementsByClassName('float-end text-success')[0]; - const IRLResult = await Utilities.CalculateIRL(NetWorthElement.innerText, Settings.IRLPriceWithCurrencyCurrency) - NetWorthElement.innerText = NetWorthElement.innerText + " ($" + IRLResult.result + " " + IRLResult.display + ")" + const IRLResult = await Utilities.CalculateIRL(NetWorthElement.innerText, Settings.IRLPriceWithCurrency.Currency) + NetWorthElement.innerHTML = NetWorthElement.innerHTML + '
(' + IRLResult.icon + IRLResult.result + ' ' + IRLResult.display + ')
' } function BestFriends() { @@ -137,7 +137,7 @@ function BestFriends() { } else { FavoriteBtn.innerText = 'Remove Best Friend Status (max ' + Utilities.Limits.BestFriends + '/' + Utilities.Limits.BestFriends + ')' } - if (UserID !== JSON.parse(window.localStorage.getItem('account_info')).ID && document.getElementById('add-friend-button').classList.contains('btn-success') === false) { + if (UserID !== JSON.parse(window.localStorage.getItem('p+account_info')).ID && document.getElementById('add-friend-button').classList.contains('btn-success') === false) { FavoriteBtn.addEventListener('click', function() { Fav(UserID, FavoriteBtn); }); @@ -147,7 +147,7 @@ function BestFriends() { document.querySelectorAll('.section-title.px-3.px-lg-0.mt-3')[0].appendChild(FavoriteBtn); function Fav(UserID, btn) { - if (UserID === JSON.parse(window.localStorage.getItem('account_info')).ID) { return } + if (UserID === JSON.parse(window.localStorage.getItem('p+account_info')).ID) { return } btn.setAttribute('disabled', 'true') chrome.storage.sync.get(['PolyPlus_BestFriends'], function(result) { diff --git a/js/account/transactions.js b/js/account/transactions.js index 8551bc0..f4e60ae 100755 --- a/js/account/transactions.js +++ b/js/account/transactions.js @@ -45,7 +45,7 @@ let Input = document.getElementById('polyplus-brickconverter-input') let Output = document.getElementById('polyplus-brickconverter-output') let Type = document.getElementById('polyplus-brickconverter-type') chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ - Type.selectedIndex = result.PolyPlus_Settings.IRLPriceWithCurrencyCurrency || 0 + Type.selectedIndex = result.PolyPlus_Settings.IRLPriceWithCurrency.Currency || 0 }); //let Package = document.getElementById('polyplus-brickconverter-package') diff --git a/js/debug.js b/js/debug.js index 536c121..a93e374 100644 --- a/js/debug.js +++ b/js/debug.js @@ -1,227 +1,233 @@ /* Debug page for Development - Accessable at /my/settings/polyplus-debug + Accessable at /my/settings/polyplus#dev */ -document.title = 'Poly+ Debug - Polytoria' -const Version = chrome.runtime.getManifest().version -document.querySelector('#main-content .container').innerHTML = ` - -
-

Poly+ Debug

-

This page is used by developers for debugging most data related things. It is unrecommended you modify any data on this page, but if you ever want to go ahead.

-
-
-
-
-
-

Version: v${Version}

-

Data Size: Loading byte(s)

- - Open GitHub -
+if (window.location.pathname.split('/')[3] === "polyplus" && window.location.hash === '#dev') { + document.title = 'Poly+ Debug - Polytoria' + const Version = chrome.runtime.getManifest().version + + document.addEventListener('DOMContentLoaded', function() { + document.querySelector('#main-content .container').innerHTML = ` + +
+

Poly+ Debug

+

This page is used by developers for debugging most data related things. It is unrecommended you modify any data on this page, but if you ever want to go ahead.

-
- Created by Index -

- Beta Testers: - -
-
- -

Set a value of the extension's local settings data

-
- - - -
- - -

Quickly clear specific parts of the extension's local data

-
- - - -
- - -

Quickly clear specific parts of the extension's local data

-
- - - - -
- -
- -
-
RUN TESTS
-
- -

will add later

-
-
- -
- -
-
DANGER ZONE!
-
- -

Quickly clear specific locations of the extension's local data

-
- - +
+
+
+
+

Version: v${Version}

+

Data Size: Loading byte(s)

+ + Open GitHub +
+
+
+ Created by Index +

+ Beta Testers: + +
+
+ +

Set a value of the extension's local settings data

+
+ + + +
+ + +

Quickly clear specific parts of the extension's local data

+
+ + + +
+ + +

Quickly clear specific parts of the extension's local data

+
+ + + + +
+ +
+ +
+
RUN TESTS
+
+ +

will add later

+
+
+ +
+ +
+
DANGER ZONE!
+
+ +

Quickly clear specific locations of the extension's local data

+
+ + +
+ + +

This will clear all local data associated with the extension

+ +
- - -

This will clear all local data associated with the extension

-
-
-
-` + ` -const CheckForUpdatesButton = document.getElementById('check-for-updates') -function CheckForUpdates() { - CheckForUpdatesButton.removeEventListener('click', CheckForUpdates) - CheckForUpdatesButton.disabled = true - fetch('https://polyplus.vercel.app/data/version.json') - .then(response => { - if (!response.ok) { - throw new Error('Network not ok') - } - return response.json() - }) - .then(data => { - if (data.version === Version || Math.floor((data.version - Version) * 10) === 0) { - CheckForUpdatesButton.innerText = 'No updates available' - } else { - CheckForUpdatesButton.innerText = Math.floor((data.version - Version) * 10) + ' updates available' - } - }) - .catch(error => {console.log(error)}); -} -CheckForUpdatesButton.addEventListener('click', CheckForUpdates); - -document.getElementById('edit-setting').addEventListener('click', function(){ - const EditSettingName = document.getElementById('edit-setting-name') - const EditSettingValue = document.getElementById('edit-setting-value') - - chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { - result = result.PolyPlus_Settings - - let NewValue = EditSettingValue.value - switch (NewValue) { - case 'true': - NewValue = true - break - case 'false': - NewValue = false - break - case 'null': - NewValue = null - break - case 'undefined': - NewValue = undefined - break - case parseInt(NewValue): - NewValue = parseInt(NewValue) - break + const CheckForUpdatesButton = document.getElementById('check-for-updates') + function CheckForUpdates() { + CheckForUpdatesButton.removeEventListener('click', CheckForUpdates) + CheckForUpdatesButton.disabled = true + fetch('https://polyplus.vercel.app/data/version.json') + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + if (data.version === Version || Math.floor((data.version - Version) * 10) === 0) { + CheckForUpdatesButton.innerText = 'No updates available' + } else { + CheckForUpdatesButton.innerText = Math.floor((data.version - Version) * 10) + ' updates available' + } + }) + .catch(error => {console.log(error)}); } - result[EditSettingName.value] = NewValue + CheckForUpdatesButton.addEventListener('click', CheckForUpdates); - chrome.storage.sync.set({ 'PolyPlus_Settings': result }, function() { - alert('Successfully set: "' + EditSettingName.value + '" to ' + NewValue) + document.getElementById('edit-setting').addEventListener('click', function(){ + const EditSettingName = document.getElementById('edit-setting-name') + const EditSettingValue = document.getElementById('edit-setting-value') + + chrome.storage.sync.get(['PolyPlus_Settings'], function(result) { + result = result.PolyPlus_Settings + + let NewValue = EditSettingValue.value + switch (NewValue) { + case 'true': + NewValue = true + break + case 'false': + NewValue = false + break + case 'null': + NewValue = null + break + case 'undefined': + NewValue = undefined + break + case parseInt(NewValue): + NewValue = parseInt(NewValue) + break + } + result[EditSettingName.value] = NewValue + + chrome.storage.sync.set({ 'PolyPlus_Settings': result }, function() { + alert('Successfully set: "' + EditSettingName.value + '" to ' + NewValue) + }); + }); }); - }); -}); -document.getElementById('reset-settings').addEventListener('click', async function(){ - let Utilities = await import(chrome.runtime.getURL('resources/utils.js')) - Utilities = Utilities.default - chrome.storage.sync.set({ 'PolyPlus_Settings': Utilities.DefaultSettings }, function() { - alert('Successfully reset settings to their defaults!') - }); -}); + document.getElementById('reset-settings').addEventListener('click', async function(){ + let Utilities = await import(chrome.runtime.getURL('resources/utils.js')) + Utilities = Utilities.default + chrome.storage.sync.set({ 'PolyPlus_Settings': Utilities.DefaultSettings }, function() { + alert('Successfully reset settings to their defaults!') + }); + }); -document.getElementById('example-pinnedgames').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [6012, 3857, 2537] }, function() { - alert('Successfully loaded example for Pinned Games!') - }); -}); + document.getElementById('example-pinnedgames').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [6012, 3857, 2537] }, function() { + alert('Successfully loaded example for Pinned Games!') + }); + }); -document.getElementById('example-bestfriends').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_BestFriends': [1, 2, 3] }, function() { - alert('Successfully loaded example for Best Friends!') - }); -}); + document.getElementById('example-bestfriends').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_BestFriends': [1, 2, 3] }, function() { + alert('Successfully loaded example for Best Friends!') + }); + }); -document.getElementById('example-itemwishlist').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_ItemWishlist': [31495, 31493, 31492] }, function() { - alert('Successfully loaded example for Item Wishlist!') - }); -}); + document.getElementById('example-itemwishlist').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_ItemWishlist': [31495, 31493, 31492] }, function() { + alert('Successfully loaded example for Item Wishlist!') + }); + }); -document.getElementById('clear-pinnedgames').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() { - alert('Successfully cleared Pinned Games!') - }); -}); + document.getElementById('clear-pinnedgames').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_PinnedGames': [] }, function() { + alert('Successfully cleared Pinned Games!') + }); + }); -document.getElementById('clear-bestfriends').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() { - alert('Successfully cleared Best Friends!') - }); -}); + document.getElementById('clear-bestfriends').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_BestFriends': [] }, function() { + alert('Successfully cleared Best Friends!') + }); + }); -document.getElementById('clear-itemwishlist').addEventListener('click', function(){ - chrome.storage.sync.set({ 'PolyPlus_ItemWishlist': [] }, function() { - alert('Successfully cleared Item Wishlist!') - }); -}); + document.getElementById('clear-itemwishlist').addEventListener('click', function(){ + chrome.storage.sync.set({ 'PolyPlus_ItemWishlist': [] }, function() { + alert('Successfully cleared Item Wishlist!') + }); + }); -document.getElementById('delete-sync').addEventListener('click', function(){ - if (confirm("Are you sure you'd like to delete all sync data associated with the extension?") === false) { return } - chrome.storage.sync.clear(function() { - alert('Successfully deleted all sync data associated with the extension!') - }); -}); + document.getElementById('delete-sync').addEventListener('click', function(){ + if (confirm("Are you sure you'd like to delete all sync data associated with the extension?") === false) { return } + chrome.storage.sync.clear(function() { + alert('Successfully deleted all sync data associated with the extension!') + }); + }); -document.getElementById('delete-local').addEventListener('click', function(){ - if (confirm("Are you sure you'd like to delete all local data associated with the extension?") === false) { return } - chrome.storage.local.clear(function() { - alert('Successfully deleted all local data associated with the extension!') - }); -}); + document.getElementById('delete-local').addEventListener('click', function(){ + if (confirm("Are you sure you'd like to delete all local data associated with the extension?") === false) { return } + chrome.storage.local.clear(function() { + alert('Successfully deleted all local data associated with the extension!') + }); + }); -document.getElementById('delete-all-data').addEventListener('click', function(){ - if (confirm("Are you sure you'd like to delete all sync and local data associated with the extension?") === false) { return } - chrome.storage.sync.clear(function() { - alert('Successfully deleted all sync data associated with the extension!') - }); - chrome.storage.local.clear(function() { - alert('Successfully deleted all local data associated with the extension!') - }); -}); + document.getElementById('delete-all-data').addEventListener('click', function(){ + if (confirm("Are you sure you'd like to delete all sync and local data associated with the extension?") === false) { return } + chrome.storage.sync.clear(function() { + alert('Successfully deleted all sync data associated with the extension!') + }); + chrome.storage.local.clear(function() { + alert('Successfully deleted all local data associated with the extension!') + }); + }); -chrome.storage.sync.getBytesInUse(["PolyPlus_Settings", "PolyPlus_PinnedGames", "PolyPlus_BestFriends", "PolyPlus_ItemWishlist"], function(bytes){ - document.getElementById('data-size').innerText = bytes.toLocaleString() -}); \ No newline at end of file + chrome.storage.sync.getBytesInUse(["PolyPlus_Settings", "PolyPlus_PinnedGames", "PolyPlus_BestFriends", "PolyPlus_ItemWishlist"], function(bytes){ + document.getElementById('data-size').innerText = bytes.toLocaleString() + }); + }) +} \ No newline at end of file diff --git a/js/everywhere.js b/js/everywhere.js index af395e6..111378c 100755 --- a/js/everywhere.js +++ b/js/everywhere.js @@ -1,5 +1,5 @@ var Settings; -let Theme = null; +let Theme = ``; (async () => { let Utilities = await import(chrome.runtime.getURL('resources/utils.js')); @@ -11,7 +11,7 @@ let Theme = null; Settings = MergeObjects(RawSettings || Utilities.DefaultSettings, Utilities.DefaultSettings); // If theme exists, create a style element to represent it - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { + if (Settings.ThemeCreator.Enabled && Settings.ThemeCreator.Enabled === true) { switch (Settings.ThemeCreator.BGImageSize) { case 0: Settings.ThemeCreator.BGImageSize = 'fit' @@ -111,43 +111,57 @@ let Theme = null; } ` } - - // Credit to @SK-Fast (also known as DevPixels) for the improved loading code (taken from his original Poly+, and reformatted to Index Poly+) - const ThemeBlob = new Blob([Theme], { type: 'text/css' }) - const ThemeURL = URL.createObjectURL(ThemeBlob) - document.head.innerHTML += `` }); + + if (Settings.HideUserAdsOn === true) { + if (Settings.HideUserAdsOn.Banners === true) { + Theme += ` + div[style^="max-width: 728px;"]:has(.text-center a[href^="/ads/"]) { + display: none; + } + ` + } + + if (Settings.HideUserAdsOn.Rectangles === true) { + Theme += ` + div[style^="max-width: 300px;"]:has(.text-center a[href^="/ads/"]) { + display: none; + } + ` + } + } + + if (Settings.HideNotifBadgesOn === true) { + Theme += ` + .notif-nav .notif-sidebar { + display: none; + } + ` + } + + // Credit to @SK-Fast (also known as DevPixels) for the improved loading code (taken from his original Poly+, and reformatted to Index Poly+) + const ThemeBlob = new Blob([Theme], { type: 'text/css' }) + const ThemeURL = URL.createObjectURL(ThemeBlob) + document.head.innerHTML += `` document.addEventListener('DOMContentLoaded', async function() { if (document.getElementsByClassName('card-header')[0] && document.getElementsByClassName('card-header')[0].innerText === ' Page not found') { return } - - /* - // Check if Theme Exists, if so Load It - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true) { - if (!(Settings.ThemeCreator.WebsiteLogo === null)) { - document.querySelector('.nav-sidebar img').setAttribute('src', Settings.ThemeCreator.WebsiteLogo) - } - } - if (Settings.ThemeCreatorOn && Settings.ThemeCreatorOn === true && Theme != null) { - document.body.prepend(Theme) - } - */ - - // Define Data - const UserData = { - ID: document.querySelector('.text-reset.text-decoration-none[href^="/users/"]').getAttribute('href').split('/')[2], - Bricks: document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g,'') - } - - window.localStorage.setItem('account_info', JSON.stringify(UserData)) + + Utilities.InjectResource('getUserDetails') document.body.setAttribute('data-URL', window.location.pathname) - if (Settings.IRLPriceWithCurrencyOn === true) { - const IRLResult = await Utilities.CalculateIRL(UserData.Bricks, Settings.IRLPriceWithCurrencyCurrency) - const BrickBalanceCount = [document.querySelector('.text-success .brickBalanceCount'), document.querySelector('.text-success .brickBalanceCont')] - BrickBalanceCount.forEach(element => {element.innerHTML += ` (${IRLResult.icon}${IRLResult.result} ${IRLResult.display})`}); + const UserData = JSON.parse(window.localStorage.getItem('p+account_info')) + + if (Settings.IRLPriceWithCurrency.Enabled === true) { + const IRLResult = await Utilities.CalculateIRL(document.querySelector('.brickBalanceCont').innerText.replace(/\s+/g,''), Settings.IRLPriceWithCurrency.Currency) + // Desktop + document.querySelector('.text-success .brickBalanceCount').innerHTML += ` (${IRLResult.icon}${IRLResult.result} ${IRLResult.display})` + + // Mobile + document.querySelector('.text-success .brickBalanceCont').innerHTML += ` (${IRLResult.icon}${IRLResult.result} ${IRLResult.display})` + //document.querySelector('.text-success .brickBalanceCont').innerHTML += `
(${IRLResult.icon}${IRLResult.result} ${IRLResult.display})
` } if (Settings.ModifyNavOn && Settings.ModifyNavOn === true) { @@ -161,6 +175,12 @@ let Theme = null; } } } + + /* + if (Settings.HideUserAdsOn === true) { + Array.from(document.querySelectorAll('.text-center:has(a[href^="/ads"])')).forEach(ad => {ad.remove()}) + } + */ if (Settings.HideNotifBadgesOn === true) { document.getElementsByClassName('notif-nav notif-sidebar').forEach(element => {element.remove();}); diff --git a/js/guilds.js b/js/guilds.js index dbc9c61..89fec4e 100644 --- a/js/guilds.js +++ b/js/guilds.js @@ -6,7 +6,7 @@ let Utilities; chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ Settings = result.PolyPlus_Settings - if (Settings.IRLPriceWithCurrencyOn === true) { + if (Settings.IRLPriceWithCurrency.Enabled === true) { (async () => { Utilities = await import(chrome.runtime.getURL('resources/utils.js')); Utilities = Utilities.default @@ -26,7 +26,7 @@ chrome.storage.sync.get(['PolyPlus_Settings'], function(result){ async function IRLPrice(item) { const Price = item.getElementsByClassName('text-success')[0] if (Price !== undefined && Price.innerText !== "Free") { - const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrencyCurrency) + const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrency.Currency) let Span = document.createElement('span') Span.classList = 'text-muted polyplus-price-tag' @@ -40,7 +40,7 @@ const observer = new MutationObserver(async function (list){ for (const record of list) { for (const element of record.addedNodes) { if (element.tagName === "DIV" && element.classList.value === 'col-auto mb-3') { - if (Settings.IRLPriceWithCurrencyOn === true) { + if (Settings.IRLPriceWithCurrency.Enabled === true) { IRLPrice(element) } } diff --git a/js/op-comments.js b/js/op-comments.js index e885f62..11a89b9 100755 --- a/js/op-comments.js +++ b/js/op-comments.js @@ -30,7 +30,6 @@ Observer.observe(Comments, {attributes: false, childList: true, subtree: false}) const LoadCreatorTag = function(element) { - console.log(element) let NameElement = element.querySelector('.text-reset[href^="/users/"]') if (Type === 'guilds') { NameElement = element.querySelector('[class^="userlink-"][href^="/users/"]') diff --git a/js/places/place-edit.js b/js/places/place-edit.js index 3d0960c..790b427 100755 --- a/js/places/place-edit.js +++ b/js/places/place-edit.js @@ -95,13 +95,13 @@ function RequestGameProfile() { async function CopyOwnedPlace() { console.log('ran function') if (PlaceData === null) { - PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID) + PlaceData = await fetch('https://api.polytoria.com/v1/places/' + 2640) PlaceData = await PlaceData.json() } - if (PlaceData.creator.id !== parseInt(JSON.parse(window.localStorage.getItem('account_info')).ID)) { + if (PlaceData.creator.id !== parseInt(JSON.parse(window.localStorage.getItem('p+account_info')).ID)) { console.log('returned') - return + //return } const DIV = document.createElement('div') diff --git a/js/places/place-view.js b/js/places/place-view.js index 1b5a6f5..41baf83 100644 --- a/js/places/place-view.js +++ b/js/places/place-view.js @@ -1,5 +1,5 @@ const PlaceID = window.location.pathname.split('/')[2] -const UserID = JSON.parse(window.localStorage.getItem('account_info')).ID +const UserID = JSON.parse(window.localStorage.getItem('p+account_info')).ID const GameCreator = document.querySelector('#main-content .card-body .col div.text-muted a[href^="/users/"]').getAttribute('href').split('/')[2] let Utilities; @@ -65,7 +65,7 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [ } } - if (Settings.IRLPriceWithCurrencyOn === true) { + if (Settings.IRLPriceWithCurrency.Enabled === true) { IRLPrice() } @@ -370,7 +370,7 @@ async function IRLPrice() { const Gamepasses = document.querySelector('#gamepasses-tabpane .row.flex-row').children for (let gamepass of Gamepasses) { const Price = gamepass.getElementsByClassName('text-success')[0] - const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrencyCurrency) + const IRLResult = await Utilities.CalculateIRL(Price.innerText, Settings.IRLPriceWithCurrency.Currency) let Span = document.createElement('span') Span.classList = 'text-muted polyplus-price-tag' diff --git a/js/store/item-view.js b/js/store/item-view.js index c0d7510..c35705e 100755 --- a/js/store/item-view.js +++ b/js/store/item-view.js @@ -1,5 +1,6 @@ const ItemID = window.location.pathname.split('/')[2] const ItemType = document.querySelector('.row .badge').innerHTML +console.log(ItemType) var Settings; var ItemWishlist; @@ -7,6 +8,7 @@ var PurchaseBtn; var WishlistBtn; var ItemOwned; var InitialOwners; +var OwnerPagesFetched = 0; var Utilities; @@ -23,7 +25,13 @@ var Utilities; } ItemOwned = (PurchaseBtn.innerText === ' Item owned' || document.querySelector('.btn[onclick="sellItem()"]') !== null) - if (Settings.IRLPriceWithCurrencyOn === true && ItemOwned === false) { + if (PurchaseBtn.getAttribute('data-seller-name')) { + PurchaseBtn.setAttribute('data-bs-toggle', 'tooltip') + PurchaseBtn.setAttribute('data-bs-title', 'Sold by ' + PurchaseBtn.getAttribute('data-seller-name')) + Utilities.InjectResource('registerTooltips') + } + + if (Settings.IRLPriceWithCurrency.Enabled === true && ItemOwned === false) { IRLPrice() } @@ -44,9 +52,14 @@ var Utilities; Sales.children[1].innerText = Owners.total.toLocaleString() } } - - if ((Settings.HoardersListOn === true && document.getElementById('resellers') !== null)) { - HoardersList(2) + + if (document.getElementById('resellers') !== null) { + if (Settings.HoardersList.Enabled === true) { + console.log(parseInt(Settings.HoardersList.MinCopies)) + HoardersList(parseInt(Settings.HoardersList.MinCopies), Settings.HoardersList.AvatarsEnabled) + } + } else if (document.getElementById('timer') && /\d/.test(document.getElementById('timer').innerText)) { + CheckOwner() } }) })(); @@ -87,7 +100,7 @@ async function IRLPrice() { Span.classList = 'text-muted polyplus-own-tag' Span.style.fontSize = '0.7rem' Span.style.fontWeight = 'normal' - const IRLResult = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrencyCurrency) + const IRLResult = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrency.Currency) Span.innerText = "($" + IRLResult.result + " " + IRLResult.display + ")" PurchaseBtn.appendChild(Span) } @@ -158,7 +171,6 @@ function HandleItemWishlist() { } function TryOnItems() { - console.log(Utilities, Utilities.MeshTypes, Utilities.TextureTypes) const Avatar = { "useCharacter": true, "items": [], @@ -175,47 +187,47 @@ function TryOnItems() { let AssetType = document.querySelector('.px-4.px-lg-0.text-muted.text-uppercase.mb-3 .badge').innerHTML const ItemThumbnail = document.getElementsByClassName('store-thumbnail')[0] - const IFrame = document.getElementsByClassName('store-thumbnail-3d')[0] + //const IFrame = document.getElementsByClassName('store-thumbnail-3d')[0] const TryIFrame = document.createElement('iframe') TryIFrame.style = 'width: 100%; height: auto; aspect-ratio: 1; border-radius: 20px;' const TryOnBtn = document.createElement('button') - TryOnBtn.classList = 'btn btn-outline-warning' + TryOnBtn.classList = 'btn btn-warning' TryOnBtn.style = 'position: absolute; bottom: 60px; right: 10px;' if (document.getElementsByClassName('3dviewtoggler')[0] === undefined) { - TryOnBtn.style.bottom = '15px;' + TryOnBtn.style.bottom = '15px' } - TryOnBtn.setAttribute('data-bs-toggle', 'tooltip') - TryOnBtn.setAttribute('data-bs-title', 'Try this item on your avatar') + //TryOnBtn.setAttribute('data-bs-toggle', 'tooltip') + //TryOnBtn.setAttribute('data-bs-title', 'Try this item on your avatar') TryOnBtn.innerHTML = '' TryOnBtn.addEventListener('click', function (){ - fetch("https://api.polytoria.com/v1/users/" + JSON.parse(window.localStorage.getItem('account_info')).ID + "/avatar") - .then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }) - .then(data => { - data.assets.forEach(item => { - switch (item.type) { - case 'hat': - Avatar.items[Avatar.items.length] = item.path || '' - break - case 'face': - Avatar.face = item.path || '' - break - case 'tool': - Avatar.tool = item.path || '' - break - case 'shirt': - Avatar.shirt = item.path || '' - break - case 'pants': - Avatar.pants = item.path || '' - break + fetch("https://api.polytoria.com/v1/users/" + JSON.parse(window.localStorage.getItem('p+account_info')).ID + "/avatar") + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); } - }); + return response.json(); + }) + .then(data => { + data.assets.forEach(item => { + switch (item.type) { + case 'hat': + Avatar.items[Avatar.items.length] = item.path || '' + break + case 'face': + Avatar.face = item.path || '' + break + case 'tool': + Avatar.tool = item.path || '' + break + case 'shirt': + Avatar.shirt = item.path || '' + break + case 'pants': + Avatar.pants = item.path || '' + break + } + }); Avatar.headColor = "#" + data.colors.head Avatar.torsoColor = "#" + data.colors.torso @@ -233,7 +245,7 @@ function TryOnItems() { return response.json(); }) .then(data => { - if (AssetType === 'tool') { + if (ItemType === 'tool') { Avatar.tool = data.url } else { Avatar.items.push(data.url) @@ -303,10 +315,10 @@ function TryOnItems() { ItemThumbnail.parentElement.appendChild(TryOnBtn) TryOnModal.children[1].prepend(TryIFrame) - Utilities.InjectResource('registerTooltips') + //Utilities.InjectResource('registerTooltips') } -async function HoardersList(min) { +async function HoardersList(min, avatars) { let Page = 0 let Tabs = document.getElementById('store-tabs') @@ -342,7 +354,11 @@ async function HoardersList(min) { }) }) + let Fetched = false Tab.addEventListener('click', async function(){ + if (Fetched === true) { return } + Fetched = true + const Owners = [] if (InitialOwners === undefined) { InitialOwners = (await (await fetch('https://api.polytoria.com/v1/store/' + ItemID + '/owners?limit=100')).json()) @@ -350,8 +366,10 @@ async function HoardersList(min) { Owners.push(...InitialOwners.inventories) // Get owners (up to 300, if needed) - if (InitialOwners.pages > 1) { - if (InitialOwners.pages > 3) {InitialOwners.pages = 3} + if (InitialOwners.pages > 3) { + InitialOwners.pages = 3 + } + if (InitialOwners.pages > 1 && OwnerPagesFetched < InitialOwners.pages) { for (let i = 1; i < InitialOwners.pages; i++) { const PageResult = (await (await fetch('https://api.polytoria.com/v1/store/' + ItemID + '/owners?limit=100&page=' + (i+1))).json()).inventories console.log(PageResult) @@ -374,7 +392,16 @@ async function HoardersList(min) { } } - let Hoarders = Object.values(Formatted).filter((x, index) => x.copies >= min).sort((a, b) => b.copies - a.copies) + let Hoarders = await new Promise(async (resolve, reject) => { + const Sorted = Object.values(Formatted).filter((x, index) => x.copies >= min).sort((a, b) => b.copies - a.copies) + if (avatars === true) { + for (let hoarder of Sorted) { + const Avatar = (await (await fetch('https://api.polytoria.com/v1/users/' + hoarder.user.id)).json()).thumbnail.icon; + hoarder.user.avatar = Avatar; + } + } + resolve(Sorted) + }) let AmountOfHoarders = Hoarders.length // Break hoarders into groups of 4 @@ -385,10 +412,15 @@ async function HoardersList(min) { TabContent.innerHTML = `
- ${ Groups[Page].map((x) => ` + ${ (Groups[Page] !== undefined) ? Groups[Page].map((x) => `
+ ${ (avatars === true) ? ` +
+ ${x.user.username} +
+ ` : '' }
@@ -412,7 +444,15 @@ async function HoardersList(min) {
`).join('') - } + : ` +
+
+

+
No hoarders
+

This item is fresh and doesn't have any hoarders yet! Come back later!

+
+
+ `}