feat: add "Re-add Copyable Places" feature
This commit is contained in:
parent
26c63d3bf6
commit
3206c6bbcd
3 changed files with 113 additions and 43 deletions
|
|
@ -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,48 +482,96 @@ 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) + ')';
|
const GetAchievementDifficulty = function(percent) {
|
||||||
}
|
if (percent >= 90 && percent <= 100) {
|
||||||
})
|
return 'Freebie';
|
||||||
.catch((error) => {
|
} else if (percent >= 80 && percent <= 89.9) {
|
||||||
console.log(error);
|
return 'Cake Walk';
|
||||||
});
|
} else if (percent >= 50 && percent <= 79.9) {
|
||||||
|
return 'Easy';
|
||||||
|
} else if (percent >= 30 && percent <= 49.9) {
|
||||||
|
return 'Moderate';
|
||||||
|
} else if (percent >= 20 && percent <= 29.9) {
|
||||||
|
return 'Challenging';
|
||||||
|
} else if (percent >= 10 && percent <= 19.9) {
|
||||||
|
return 'Hard';
|
||||||
|
} else if (percent >= 5 && percent <= 9.9) {
|
||||||
|
return 'Extreme';
|
||||||
|
} else if (percent >= 1 && percent <= 4.9) {
|
||||||
|
return 'Insane';
|
||||||
|
} else if (percent >= 0 && percent <= 0.9) {
|
||||||
|
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) + ')';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetAchievementDifficulty(percent) {
|
async function ReaddCopyable() {
|
||||||
if (percent >= 90 && percent <= 100) {
|
if (PlaceDetails === null) {
|
||||||
return 'Freebie';
|
PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json());
|
||||||
} else if (percent >= 80 && percent <= 89.9) {
|
}
|
||||||
return 'Cake Walk';
|
|
||||||
} else if (percent >= 50 && percent <= 79.9) {
|
if (PlaceDetails.isCopyable) {
|
||||||
return 'Easy';
|
const TitleCardButtons = document.querySelector('.card:has(h1.my-0) .col-auto[style^="m"]')
|
||||||
} else if (percent >= 30 && percent <= 49.9) {
|
|
||||||
return 'Moderate';
|
const DownloadCopyButton = document.createElement('button')
|
||||||
} else if (percent >= 20 && percent <= 29.9) {
|
DownloadCopyButton.style.padding = '9px'
|
||||||
return 'Challenging';
|
DownloadCopyButton.classList = 'px-4 btn btn-success my-2'
|
||||||
} else if (percent >= 10 && percent <= 19.9) {
|
DownloadCopyButton.setAttribute('data-bs-toggle', 'tooltip')
|
||||||
return 'Hard';
|
DownloadCopyButton.setAttribute('data-bs-title', 'Download this place')
|
||||||
} else if (percent >= 5 && percent <= 9.9) {
|
DownloadCopyButton.innerHTML = '<i class="fas fa-download"></i>'
|
||||||
return 'Extreme';
|
|
||||||
} else if (percent >= 1 && percent <= 4.9) {
|
if (TitleCardButtons.children[0].children.length === 0) {
|
||||||
return 'Insane';
|
TitleCardButtons.children[0].innerHTML = '<div class="col-auto px-1"></div>'
|
||||||
} else if (percent >= 0 && percent <= 0.9) {
|
TitleCardButtons.children[0].appendChild(DownloadCopyButton)
|
||||||
return 'Impossible';
|
} 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
var tooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]');
|
var tooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]');
|
||||||
var list = [...tooltips].map((tool) => new bootstrap.Tooltip(tool));
|
var list = [...tooltips].map((tool) => new bootstrap.Tooltip(tool));
|
||||||
|
|
@ -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"> </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"> </span>
|
<span class="indicator"> </span>
|
||||||
|
|
|
||||||
Reference in a new issue