From 066babda56c5319bcec5e8aa0daf1bc6d84f5366 Mon Sep 17 00:00:00 2001 From: Index Date: Tue, 26 Mar 2024 20:29:39 -0500 Subject: [PATCH] Add "Show Approximate Place Revenue" Feature - Add "Show Approximate Place Revenue" feature - Link roadmap in the README.md --- README.md | 3 ++ js/places/place-view.js | 110 +++++++++++++++++++++++++++++++++------- settings.html | 11 ++++ 3 files changed, 107 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 09b2aa7..c4c7a8f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ > [!IMPORTANT] > This extension is currently in BETA. If you find any bugs, please report them in this repository's issues section as it'd be a great help towards development of the extension. +> [!ROADMAP] +> Want to learn what's in store for Poly+? Check out the roadmap [here](https://github.com/users/indexxing/projects/2)! + # Poly+ Poly+ is an upcoming quality-of-life browser extension for the Polytoria website! The extension provides tons of improvements to improve your experience on Polytoria! Visit the website [here](https://polyplus.vercel.app/)! diff --git a/js/places/place-view.js b/js/places/place-view.js index 486c33f..088d0de 100644 --- a/js/places/place-view.js +++ b/js/places/place-view.js @@ -1,5 +1,6 @@ -const GameID = window.location.pathname.split('/')[2] +const PlaceID = window.location.pathname.split('/')[2] const UserID = JSON.parse(window.localStorage.getItem('account_info')).ID +const GameCreator = document.querySelector('#main-content .card-body .col div.text-muted a[href^="/users/"]').getAttribute('href').split('/')[2] let Utilities; @@ -7,8 +8,11 @@ var Settings; var PinnedGamesData = [] let GamePinned; +let InfoColumns = document.querySelectorAll('#main-content .col:has(#likes-data-container) .card:last-child ul') +let CalculateRevenueButton; + !(() => { - if (GameID === undefined) { return } + if (PlaceID === undefined) { return } const DataContainer = document.getElementById('likes-data-container') const RatingsData = { @@ -64,6 +68,30 @@ let GamePinned; if (Settings.StoreOwnTagsOn === true) { OwnedTags() } + + if (Settings.ShowPlaceRevenueOn === true) { + const NameRow = document.createElement('li') + NameRow.innerText = 'Revenue:' + + CalculateRevenueButton = document.createElement('li') + CalculateRevenueButton.classList = 'fw-normal text-success' + CalculateRevenueButton.style.letterSpacing = '0px' + CalculateRevenueButton.innerHTML = ` + $ Calculate + ` + + InfoColumns[0].appendChild(NameRow) + InfoColumns[1].appendChild(CalculateRevenueButton) + + let Calculating = false + CalculateRevenueButton.addEventListener('click', function() { + if (Calculating === false) { + Calculating = true + CalculateRevenueButton.innerText = '$ Calculating...' + PlaceRevenue() + } + }) + } }); })() @@ -75,7 +103,7 @@ async function PinnedGames() { PinBtn.classList = 'btn btn-warning btn-sm'; PinBtn.style = 'position: absolute; right: 0; margin-right: 7px;' - if (PinnedGamesData[GameID]) { + if (PinnedGamesData[PlaceID]) { PinBtn.innerHTML = ' Un-pin'; } else { if (PinnedGames.length !== 5) { @@ -90,7 +118,7 @@ async function PinnedGames() { PinBtn.classList = 'btn btn-warning btn-sm'; PinBtn.style = 'position: absolute; right: 0; margin-right: 7px;' - if (PinnedGamesData.includes(parseInt(GameID))) { + if (PinnedGamesData.includes(parseInt(PlaceID))) { PinBtn.innerHTML = ' Un-pin'; } else { if (PinnedGamesData.length !== 5) { @@ -107,23 +135,23 @@ async function PinnedGames() { chrome.storage.sync.get(['PolyPlus_PinnedGames'], function(result) { PinnedGamesData = result.PolyPlus_PinnedGames || []; /* - const Index = PinnedGames.indexOf(parseInt(GameID)) + const Index = PinnedGames.indexOf(parseInt(PlaceID)) if (Index !== -1) { - //delete PinnedGames[GameID] + //delete PinnedGames[PlaceID] PinnedGames.splice(Index, 1) PinBtn.innerHTML = ' Pin' } else { - //PinnedGames[GameID] = {lastVisited: new Date()} - PinnedGames.push(parseInt(GameID)) + //PinnedGames[PlaceID] = {lastVisited: new Date()} + PinnedGames.push(parseInt(PlaceID)) PinBtn.innerHTML = ' Un-pin' } */ - const Index = PinnedGamesData.indexOf(parseInt(GameID)); + const Index = PinnedGamesData.indexOf(parseInt(PlaceID)); if (Index !== -1) { PinnedGamesData.splice(Index, 1); PinBtn.innerHTML = ' Pin' } else { - PinnedGamesData.push(parseInt(GameID)); + PinnedGamesData.push(parseInt(PlaceID)); PinBtn.innerHTML = ' Un-pin' } @@ -144,7 +172,7 @@ async function PinnedGames() { PinnedGamesData = result.PolyPlus_PinnedGames || []; /* - if (PinnedGamesData[GameID]) { + if (PinnedGamesData[PlaceID]) { PinBtn.innerHTML = ' Un-pin' } else { if (PinnedGamesData.length !== 5) { @@ -156,7 +184,7 @@ async function PinnedGames() { } } */ - if (PinnedGamesData.includes(parseInt(GameID))) { + if (PinnedGamesData.includes(parseInt(PlaceID))) { PinBtn.innerHTML = ' Un-pin' } else { if (PinnedGamesData.length !== 5) { @@ -179,7 +207,6 @@ async function InlineEditing() { // Add the ability to edit the game's genre // Improve editing visuals overall - const GameCreator = document.querySelector('#main-content .card-body .col div.text-muted a[href^="/users/"]').getAttribute('href').split('/')[2] if (GameCreator !== UserID) { return } @@ -278,7 +305,7 @@ async function InlineEditing() { if (Editing === false) { const Send = new FormData() Send.append("_csrf", document.querySelector('input[name="_csrf"]').value) - Send.append("id", GameID) + Send.append("id", PlaceID) for (let input of Inputs) { console.log('start of loop') Send.append(input.name, input.element.value) @@ -314,7 +341,7 @@ async function InlineEditing() { if (Editing === false) { const Send = new FormData() Send.append("_csrf", document.querySelector('input[name="_csrf"]').value) - Send.append("id", GameID) + Send.append("id", PlaceID) Send.append("name", PlaceTitle.innerText || '') fetch('/create/place/update', {method:"POST",body:Send}) @@ -394,7 +421,7 @@ async function IRLPrice() { async function OwnedTags() { /* - This feature is disabled due to the the public API for user inventories is broken when specifying an asset type + This feature is disabled due to Polytoria website now having this without the use of an extension - items are now grayed out if they are owned */ return const Response = await fetch('https://api.polytoria.com/v1/users/' + UserID + '/inventory/') @@ -409,4 +436,53 @@ async function OwnedTags() { const GamePassID = gamepass.getElementsByTagName('a')[0].getAttribute('href').split('/') console.log(GamePassID) } -} \ No newline at end of file +} + +async function PlaceRevenue() { + console.log('place revenue ran') + const Visits = parseInt(document.querySelector('li:has(i.fad.fa-users.text-muted[style])').innerText) + const BricksPerView = 5 + let Revenue = (round5(Visits) / 5) + + let CreatorDetails = await fetch('https://api.polytoria.com/v1/users/' + GameCreator) + CreatorDetails = await CreatorDetails.json() + + let CreatorTax = 0.35 + switch (CreatorDetails.membershipType) { + case 'plus': + CreatorTax = 0.25 + break + case 'plusDeluxe': + CreatorTax = 0.15 + break + } + + console.log('CREATOR TAX: ' + CreatorTax) + + fetch(`https://api.polytoria.com/v1/places/${PlaceID}/gamepasses`) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + for (let gamepass of data.gamepasses) { + const PriceAfterTax = Math.floor(gamepass.asset.price - (gamepass.asset.price * CreatorTax)) + Revenue += (PriceAfterTax * gamepass.asset.sales) + } + + const ResultText = document.createElement('li') + ResultText.classList = 'fw-normal text-success' + ResultText.style.letterSpacing = '0px' + ResultText.innerHTML = ` ~` + Revenue.toLocaleString() + + CalculateRevenueButton.remove() + InfoColumns[1].appendChild(ResultText) + }) + .catch(error => { + console.log(error) + }) +} + +function round5(number) { const remainder = number % 5; if (remainder < 2.5) { return number - remainder; } else { return number + (5 - remainder); } } \ No newline at end of file diff --git a/settings.html b/settings.html index ed41045..cc492e4 100755 --- a/settings.html +++ b/settings.html @@ -501,6 +501,17 @@
Quickly see how many bricks a user spent on their avatar!

+

+   + + Show Approximate Place Revenue + + +
+ Quickly see how many bricks a user has gained from one of their places! +
+ * Gamepass revenue is calculated assuming the price hasn't changed and all users that bought the gamepass, bought it at the same price. +

EXPERIMENTAL SETTINGS