feat: add "Re-add Copyable Places" feature

This commit is contained in:
Index 2024-07-02 13:34:29 -05:00
parent 26c63d3bf6
commit 3206c6bbcd
3 changed files with 113 additions and 43 deletions

View file

@ -3,6 +3,7 @@ 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]; const GameCreator = document.querySelector('#main-content .card-body .col div.text-muted a[href^="/users/"]').getAttribute('href').split('/')[2];
let Utilities; let Utilities;
let PlaceDetails = null;
var Settings; var Settings;
var PinnedGamesData = []; var PinnedGamesData = [];
@ -113,6 +114,10 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
} }
} }
} }
if (Settings.ReaddCopyableOn === true || 1 === 1) {
ReaddCopyable()
}
}); });
})(); })();
@ -391,8 +396,9 @@ async function IRLPrice() {
async function PlaceRevenue() { async function PlaceRevenue() {
const BricksPerView = 5; const BricksPerView = 5;
let PlaceDetails = await fetch('https://api.polytoria.com/v1/places/' + PlaceID); if (PlaceDetails === null) {
PlaceDetails = await PlaceDetails.json(); PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json());
}
let CreatorDetails = await fetch('https://api.polytoria.com/v1/users/' + GameCreator); let CreatorDetails = await fetch('https://api.polytoria.com/v1/users/' + GameCreator);
CreatorDetails = await CreatorDetails.json(); CreatorDetails = await CreatorDetails.json();
@ -476,31 +482,12 @@ function AchievementProgressBar() {
AchievementsTab.prepend(ProgressBar); AchievementsTab.prepend(ProgressBar);
} }
function AchievementEarnedPercentage() { async function AchievementEarnedPercentage() {
fetch('https://api.polytoria.com/v1/places/' + PlaceID) if (PlaceDetails === null) {
.then((response) => { PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json());
if (!response.ok) {
throw new Error('Network not ok');
}
return response.json();
})
.then((data) => {
const UserCount = data.uniqueVisits;
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 + '%, ' + GetAchievementDifficulty(PercentageOfPlayers) + ')';
}
})
.catch((error) => {
console.log(error);
});
} }
function GetAchievementDifficulty(percent) { const GetAchievementDifficulty = function(percent) {
if (percent >= 90 && percent <= 100) { if (percent >= 90 && percent <= 100) {
return 'Freebie'; return 'Freebie';
} else if (percent >= 80 && percent <= 89.9) { } else if (percent >= 80 && percent <= 89.9) {
@ -521,3 +508,70 @@ function GetAchievementDifficulty(percent) {
return 'Impossible'; return 'Impossible';
} }
} }
const UserCount = PlaceDetails.uniqueVisits;
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 + '%, ' + GetAchievementDifficulty(PercentageOfPlayers) + ')';
}
}
async function ReaddCopyable() {
if (PlaceDetails === null) {
PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json());
}
if (PlaceDetails.isCopyable) {
const TitleCardButtons = document.querySelector('.card:has(h1.my-0) .col-auto[style^="m"]')
const DownloadCopyButton = document.createElement('button')
DownloadCopyButton.style.padding = '9px'
DownloadCopyButton.classList = 'px-4 btn btn-success my-2'
DownloadCopyButton.setAttribute('data-bs-toggle', 'tooltip')
DownloadCopyButton.setAttribute('data-bs-title', 'Download this place')
DownloadCopyButton.innerHTML = '<i class="fas fa-download"></i>'
if (TitleCardButtons.children[0].children.length === 0) {
TitleCardButtons.children[0].innerHTML = '<div class="col-auto px-1"></div>'
TitleCardButtons.children[0].appendChild(DownloadCopyButton)
} else {
TitleCardButtons.children[0].prepend(DownloadCopyButton)
}
DownloadCopyButton.addEventListener('click', async function () {
let CreatorToken = (await (await fetch('https://polytoria.com/api/places/edit', {
method: 'POST',
body: JSON.stringify({placeID: PlaceID})
})).json()).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 DownloadURL = URL.createObjectURL(data);
const Link = document.createElement('a');
Link.href = DownloadURL;
Link.download = PlaceDetails.name + '.poly';
document.body.appendChild(Link);
Link.click();
Link.remove();
})
.catch((error) => {
console.log(error);
});
});
}
}

View file

@ -759,6 +759,22 @@
* This feature will be expanded to allow you to pick from a list of value lists (list-inception), if any prominent value lists pop-up in the future! * This feature will be expanded to allow you to pick from a list of value lists (list-inception), if any prominent value lists pop-up in the future!
</span> </span>
</div> </div>
<div class="setting-container" id="collectibles-inventory-category">
<span class="indicator">&nbsp;</span>
<span class="title">
Re-add Copyable Places
</span>
<div class="setting-buttons">
<button class="btn btn-sm toggle-btn" data-setting="CollectibleInventoryCatOn">Toggle</button>
</div>
<br />
<span class="desc">
Download "copyable" places on Polytoria again!
</span>
<span class="warning">
* This feature does not make it possible to set your place(s) as "copyable"
</span>
</div>
<!--- <!---
<div class="setting-container" id="auto-ad-bidding"> <div class="setting-container" id="auto-ad-bidding">
<span class="indicator">&nbsp;</span> <span class="indicator">&nbsp;</span>