diff --git a/js/places/place-edit.js b/js/places/place-edit.js index 02491e7..3d0960c 100755 --- a/js/places/place-edit.js +++ b/js/places/place-edit.js @@ -1,17 +1,21 @@ -const ID = window.location.pathname.split('/')[3] +const PlaceID = window.location.pathname.split('/')[3] const Form = document.querySelector('form[action="/create/place/update"]') var Settings; +var PlaceData = null !(async () => { ActivityToggle() //RequestGameProfile() + CopyOwnedPlace() })() async function ActivityToggle() { - const Response = await fetch('https://api.polytoria.com/v1/places/'+ID) - let Status = await Response.json() - Status = Status.isActive + if (PlaceData === null) { + PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID) + PlaceData = await PlaceData.json() + } + let Status = PlaceData.isActive const DIV = document.createElement('div') DIV.classList = 'form-group mt-4' @@ -32,7 +36,7 @@ async function ActivityToggle() { DIV.appendChild(ActivityBtn) ActivityBtn.addEventListener('click', function() { - fetch(`https://polytoria.com/api/places/${ID}/toggle-active`, { + fetch(`https://polytoria.com/api/places/${PlaceID}/toggle-active`, { method: "POST", headers: { 'Content-Type': 'application/json', @@ -84,6 +88,71 @@ function RequestGameProfile() { cardBg: CardBody.children[4].value, text: CardBody.children[5].value } - window.location.href = 'https://polyplus.vercel.app/app/game-profile.html?gameId=' + ID + '&profile=' + encodeURIComponent(btoa(JSON.stringify(Result))) + window.location.href = 'https://polyplus.vercel.app/app/game-profile.html?gameId=' + PlaceID + '&profile=' + encodeURIComponent(btoa(JSON.stringify(Result))) }); +} + +async function CopyOwnedPlace() { + console.log('ran function') + if (PlaceData === null) { + PlaceData = await fetch('https://api.polytoria.com/v1/places/' + PlaceID) + PlaceData = await PlaceData.json() + } + + if (PlaceData.creator.id !== parseInt(JSON.parse(window.localStorage.getItem('account_info')).ID)) { + console.log('returned') + return + } + + const DIV = document.createElement('div') + DIV.classList = 'form-group mt-4' + DIV.innerHTML = ` + +
+ + ` + + Form.insertBefore(DIV, Form.children[Form.children.length-1]) + + const DownloadButton = DIV.getElementsByTagName('button')[0] + DownloadButton.addEventListener('click', async function() { + console.log('clicked download epic') + + 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() + CreatorToken = CreatorToken.token + + fetch(`https://api.polytoria.com/v1/places/get-place?id=${PlaceID}&tokenType=creator`, { + headers: { + 'Authorization': CreatorToken + } + }) + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.blob() + }) + .then(data => { + //const JSONBlob = new Blob([data], {type: "application/xml"}) + const DownloadURL = URL.createObjectURL(data) + + const Link = document.createElement('a') + Link.href = DownloadURL + Link.download = PlaceData.name + '.poly' + document.body.appendChild(Link) + Link.click() + Link.remove() + }) + .catch(error => {console.log(error)}); + }) } \ No newline at end of file diff --git a/js/places/place-view.js b/js/places/place-view.js index 31903c1..25d56ab 100644 --- a/js/places/place-view.js +++ b/js/places/place-view.js @@ -12,7 +12,7 @@ let InfoColumns = document.querySelectorAll('#main-content .col:has(#likes-data- let CalculateRevenueButton; const AchievementsTab = document.getElementById('achievements-tabpane') -const Achievements = Array.from(AchievementsTab.children) +const Achievements = Array.from(AchievementsTab.getElementsByClassName('card')) !(() => { if (PlaceID === undefined) { return } @@ -68,10 +68,6 @@ const Achievements = Array.from(AchievementsTab.children) })(); } - if (Settings.StoreOwnTagsOn === true) { - OwnedTags() - } - if (Settings.ShowPlaceRevenueOn === true) { const NameRow = document.createElement('li') NameRow.innerText = 'Revenue:' @@ -99,6 +95,12 @@ const Achievements = Array.from(AchievementsTab.children) if (AchievementsTab.getElementsByClassName('display-3')[0] === undefined) { AchievementProgressBar() AchievementEarnedPercentage() + + for (let achievement of Achievements) { + if ((achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) === false) { + achievement.style.opacity = '0.5' + } + } } }); })() @@ -339,39 +341,9 @@ async function InlineEditing() { console.log('Error while editing game') }); } - - /* - PlaceTitleSpan.setAttribute('contenteditable', Editing.toString()) - if (PlaceDesc !== null) { - console.log('Description exists') - PlaceDesc.setAttribute('contenteditable', Editing.toString()) - } - if (Editing === false) { - const Send = new FormData() - Send.append("_csrf", document.querySelector('input[name="_csrf"]').value) - Send.append("id", PlaceID) - Send.append("name", PlaceTitle.innerText || '') - - fetch('/create/place/update', {method:"POST",body:Send}) - .then(response => { - if (!response.ok) { - throw new Error('Network not ok') - } - return response.text() - }) - .then(data => { - console.log('Successfully edited game') - }) - .catch(error => { - console.log('Error while editing game') - }); - } - */ }); } -//const Data = JSON.parse('{"gameTitle": "Hyper[Fart]","bg": "#000","accent": "#007bff","secondary": "#","cardBg": "#313131","font": "","text": "#fff"}') -const Data = JSON.parse('{"gameTitle":"Isolation: Brix High School","bg":"#0148af","accent":"#986c6a","secondary":"#b7d3f2","cardBg":"#313131","text":"#fff"}') async function GameProfiles(data) { return data = Data @@ -427,25 +399,6 @@ async function IRLPrice() { } } -async function OwnedTags() { - /* - 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/') - const Gamepasses = document.querySelector('#gamepasses-tabpane .row.flex-row').children - for (let gamepass of Gamepasses) { - const GamePassID = gamepass.getElementsByTagName('a')[0].getAttribute('href').split('/') - console.log(GamePassID) - } - - const Achievements = document.querySelector('#achievements-tabpane .row.flex-row').children - for (let gamepass of Achievements) { - const GamePassID = gamepass.getElementsByTagName('a')[0].getAttribute('href').split('/') - console.log(GamePassID) - } -} - async function PlaceRevenue() { const Visits = parseInt(document.querySelector('li:has(i.fad.fa-users.text-muted[style])').innerText) const BricksPerView = 5 @@ -492,12 +445,60 @@ async function PlaceRevenue() { function round5(number) { const remainder = number % 5; if (remainder < 2.5) { return number - remainder; } else { return number + (5 - remainder); } } +function ImprovedAchievements() { + const AchievementCount = Achievements.length + let AchievementsEarned = 0 + + for (let achievement of Achievements) { + Achieved = (achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) + + if (Achieved === true) { + achievement.style.borderColor = 'gold' + AchievementsEarned++ + } + } + + const PercentageEarned = ((AchievementsEarned*100)/AchievementCount).toFixed(0) + + const ProgressBar = document.createElement('div') + ProgressBar.role = 'progressbar' + ProgressBar.classList = 'progress' + ProgressBar.style.background = '#000' + ProgressBar.ariaValueNow = PercentageEarned + ProgressBar.ariaValueMin = "0" + ProgressBar.ariaValueMax = "100" + ProgressBar.innerHTML = `
${PercentageEarned}%
` + + AchievementsTab.prepend(document.createElement('hr')) + AchievementsTab.prepend(ProgressBar) + + fetch('https://api.polytoria.com/v1/users/') + .then(response => { + if (!response.ok) { + throw new Error('Network not ok') + } + return response.json() + }) + .then(data => { + const UserCount = data.total + for (let achievement of Achievements) { + const OwnerText = achievement.getElementsByClassName('text-muted small my-0')[0] + // thanks to Stackoverflow on how to remove everything except numbers from string + const OwnerCount = parseInt(OwnerText.innerText.replace(/[^0-9]/g, '')) + const PercentageOfPlayers = ((OwnerCount*100)/UserCount).toFixed(2) + + OwnerText.innerHTML += " (" + PercentageOfPlayers + "%)" + } + }) + .catch(error => {console.log(error)}); +} + function AchievementProgressBar() { const AchievementCount = Achievements.length let AchievementsEarned = 0 for (let achievement of Achievements) { - Achieved = (achievement.getElementsByClassName('fad fa-calendar')[0] !== undefined) + Achieved = (achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) if (Achieved === true) { AchievementsEarned++ @@ -520,7 +521,7 @@ function AchievementProgressBar() { } function AchievementEarnedPercentage() { - fetch ('https://api.polytoria.com/v1/users/') + fetch('https://api.polytoria.com/v1/users/') .then(response => { if (!response.ok) { throw new Error('Network not ok') @@ -536,13 +537,6 @@ function AchievementEarnedPercentage() { const PercentageOfPlayers = ((OwnerCount*100)/UserCount).toFixed(2) OwnerText.innerHTML += " (" + PercentageOfPlayers + "%)" - - /* - const PercentageText = document.createElement('small') - PercentageText.style.fontSize = '0.75rem;' - PercentageText.innerText = PercentageOfPlayers + '% of Polytoria players have this achievement' - achievement.getElementsByClassName('col-10')[0].appendChild(PercentageText) - */ } }) .catch(error => {console.log(error)}); diff --git a/old.js b/old.js deleted file mode 100755 index 55219ce..0000000 --- a/old.js +++ /dev/null @@ -1,97 +0,0 @@ -let CurrencyNames = [ - "USD", - "EUR", - "CAD", - "GBP", - "MXN", - "AUD", - "TRY" -] - -let Divides = [ - 100, - 550, - 1150, - 2750, - 6000, - 12500 -] - -let Currencies = [ - [ - 0.99, // USD - 1.12, // EUR - 1.23, // CAD - 0.81, // GBP - 19.28, // MXN - 1.42, // AUD - 15.83, // TRY - ], - - [ - 4.99, // USD - 5.59, // EUR - 6.21, // CAD - 4.05, // GBP - 96.44, // MXN - 7.38, // AUD - 80.39, // TRY - ], - - [ - 9.99, // USD - 11.18, // EUR - 12.34, // CAD - 8.10, // GBP - 192.80, // MXN - 14.76, // AUD - 158.33, // TRY - ], - - [ - 24.99, // USD - 27.39, // EUR - 29.22, // CAD - 19.20, // GBP - 475.60, // MXN - 34.92, // AUD - 396.66, // TRY - ], - - [ - 49.99, // USD - 55.94, // EUR - 58.44, // CAD - 36.40, // GBP - 951.20, // MXN - 73.84, // AUD - 793.32, // TRY - ], - - [ - 99.99, // USD - 111.88, // EUR - 116.88, // CAD - 72.80, // GBP - 1902.40, // MXN - 147.68, // AUD - 1586.64, // TRY - ] -] - -let UnitPrices = [ - {}, - {}, - {}, - {}, - {}, - {} -] - -Currencies.forEach((_value, _index) => { - Currencies[_index].forEach((value, index) => { - UnitPrices[_index][CurrencyNames[index]] = (value / Divides[_index]) - }) -}); - -console.log(JSON.stringify(UnitPrices)) \ No newline at end of file