feat: "Multi-Whitelist" and "Clear Whitelist" features

This commit is contained in:
Index 2024-07-19 21:25:48 -05:00
parent c6a3ce2c69
commit 908637e72e
5 changed files with 183 additions and 7 deletions

View file

@ -98,7 +98,14 @@ const DefaultSettings = {
}, },
ReaddCopyablePlacesOn: true, ReaddCopyablePlacesOn: true,
TimePlayedOn: true, TimePlayedOn: true,
HomeJoinFriendsButtonOn: true HomeJoinFriendsButtonOn: true,
ImprovedPlaceManagement: {
Enabled: true,
QuickActivityToggleOn: true,
PlaceFileDownloadOn: true,
MultiWhitelistOn: true,
ClearWhitelistOn: true
}
} }
// ON EXTENSION INSTALL / RELOAD // ON EXTENSION INSTALL / RELOAD

View file

@ -4,10 +4,41 @@ const Form = document.querySelector('form[action="/create/place/update"]');
var Settings; var Settings;
var PlaceData = null; var PlaceData = null;
let Utilities;
!(async () => { !(async () => {
Utilities = (await import(chrome.runtime.getURL('resources/utils.js')))
.default;
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Settings = result.PolyPlus_Settings || {
ImprovedPlaceManagement: {
Enabled: true,
QuickActivityToggleOn: true,
PlaceFileDownloadOn: true,
MultiWhitelistOn: true,
ClearWhitelistOn: true
}
}
if (Settings.ImprovedPlaceManagement.Enabled) {
if (Settings.ImprovedPlaceManagement.QuickActivityToggleOn && Settings.ImprovedPlaceManagement.QuickActivityToggleOn === true) {
ActivityToggle(); ActivityToggle();
//RequestGameProfile() }
if (Settings.ImprovedPlaceManagement.PlaceFileDownloadOn && Settings.ImprovedPlaceManagement.PlaceFileDownloadOn === true) {
CopyOwnedPlace(); CopyOwnedPlace();
}
if (Settings.ImprovedPlaceManagement.MultiWhitelistOn && Settings.ImprovedPlaceManagement.MultiWhitelistOn === true) {
MultiWhitelist();
}
if (Settings.ImprovedPlaceManagement.ClearWhitelistOn && Settings.ImprovedPlaceManagement.ClearWhitelistOn === true) {
ClearWhitelist();
}
}
})
})(); })();
async function ActivityToggle() { async function ActivityToggle() {
@ -141,3 +172,103 @@ async function CopyOwnedPlace() {
}); });
}); });
} }
function MultiWhitelist(){
const WhitelistCard = document.querySelector('.card:has(#whitelist-username)')
const MultiWhitelistCard = document.createElement('card')
MultiWhitelistCard.classList = 'card mt-3'
MultiWhitelistCard.innerHTML = `
<div class="card-header">
<i class="fa-duotone fa-solid fa-vial-circle-check"></i>
Multi-Whitelist
</div>
<div class="card-body">
<textarea class="form-control bg-dark mb-2" placeholder="Usernames (separated by lines).." style="min-height: 250px;"></textarea>
<button class="btn btn-primary">
<i class="fa-duotone fa-solid fa-users"></i>
Whitelist
</button>
</div>
`
WhitelistCard.parentElement.appendChild(MultiWhitelistCard)
const MultiWhitelistSubmitButton = MultiWhitelistCard.getElementsByTagName('button')[0]
MultiWhitelistSubmitButton.addEventListener('click', async function(){
const Usernames = MultiWhitelistSubmitButton.previousElementSibling.value.split('\n').filter((x) => x !== "")
MultiWhitelistSubmitButton.previousElementSibling.disabled = true
if (Usernames.length > 0) {
for (let username of Usernames) {
const WhitelistAddRequest = (await (await fetch('https://polytoria.com/api/create/whitelist', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
placeID: PlaceID,
username: username
})
})).json())
}
window.location.reload()
}
})
}
function ClearWhitelist() {
const WhitelistCard = document.querySelector('.card:has(#whitelist-username)')
const ClearWhitelistButton = document.createElement('button')
ClearWhitelistButton.classList = 'btn btn-danger btn-sm'
ClearWhitelistButton.style = 'position: absolute; top: 0; right: 0; margin: 4px;'
ClearWhitelistButton.innerHTML = '<i class="fa-duotone fa-solid fa-broom-wide"></i> Clear'
WhitelistCard.children[0].appendChild(ClearWhitelistButton)
let WhitelistData = null
let ClearPending = false
ClearWhitelistButton.addEventListener('click', async function(){
if (ClearPending === false) {
ClearPending = true
ClearWhitelistButton.innerText = 'Are you sure?'
setTimeout(() => {
if (ClearPending === true) {
ClearPending = false;
ClearWhitelistButton.innerHTML = '<i class="fa-duotone fa-solid fa-broom-wide"></i> Clear'
}
}, 3000);
} else {
ClearPending = false
ClearWhitelistButton.innerHTML = '<i class="fa-duotone fa-solid fa-broom-wide"></i> Clear'
if (confirm('Are you sure you\'d like to clear all of this place\'s whitelist')) {
if (WhitelistData === null) {
const InitialWhitelist = (await (await fetch('https://polytoria.com/api/create/whitelist?placeID=' + PlaceID + '&page=1')).json())
WhitelistData = [...InitialWhitelist.data]
if (InitialWhitelist.meta.lastPage > 1) {
for (let page = 1; page < InitialWhitelist.meta.lastPage; page++) {
const PageResult = (await (await fetch('https://polytoria.com/api/create/whitelist?placeID=' + PlaceID + '&page=' + (page+1))).json())
WhitelistData.push(...PageResult.data)
}
}
for (let id of WhitelistData.map((x) => x.user.id)) {
Utilities.RatelimitRepeatingFetch('https://polytoria.com/api/create/remove-whitelist', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
placeID: PlaceID,
userID: id
})
})
}
window.location.reload()
}
}
}
})
}

View file

@ -33,8 +33,8 @@
}, },
{ {
"matches": ["https://polytoria.com/create/place/**"], "matches": ["https://polytoria.com/create/place/**/access"],
"js": ["/js/places/place-edit.js"] "js": ["/js/create/place-access.js"]
}, },
{ {

View file

@ -117,7 +117,14 @@ export default {
OpacityOn: true OpacityOn: true
}, },
TimePlayedOn: true, TimePlayedOn: true,
HomeJoinFriendsButtonOn: true HomeJoinFriendsButtonOn: true,
ImprovedPlaceManagement: {
Enabled: true,
QuickActivityToggleOn: true,
PlaceFileDownloadOn: true,
MultiWhitelistOn: true,
ClearWhitelistOn: true
}
}, },
Limits: { Limits: {
PinnedGames: 10, PinnedGames: 10,

View file

@ -810,6 +810,37 @@
Quickly join your friends' servers by clicking the play button inside the tooltip in the "Friends" section of the homepage. Quickly join your friends' servers by clicking the play button inside the tooltip in the "Friends" section of the homepage.
</span> </span>
</div> </div>
<div class="setting-container" id="improved-place-management">
<span class="badge bg-primary mb-1">Now a Setting!</span>
<br>
<span class="indicator">&nbsp;</span>
<span class="title">
Improved Place Management
</span>
<div class="setting-buttons">
<button class="btn btn-sm toggle-btn" data-setting="Enabled" data-parent="ImprovedPlaceManagement">Toggle</button>
</div>
<br />
<span class="desc">
Develop the next hit game easier with a few management tools!
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="quick-activity-toggle" data-setting="QuickActivityToggleOn" data-parent="ImprovedPlaceManagement" />
<label class="form-check-label" for="quick-activity-toggle"> Quick Place Activity Toggle </label>
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="download-place-file-button" data-setting="PlaceFileDownloadOn" data-parent="ImprovedPlaceManagement" />
<label class="form-check-label" for="download-place-file-button"> Download Place File Button </label>
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="multi-whitelist" data-setting="MultiWhitelistOn" data-parent="ImprovedPlaceManagement" />
<label class="form-check-label" for="multi-whitelist"> <span class="badge bg-primary mb-1">New in v1.3!</span> Multi-Whitelist Several Users </label>
</span>
<span class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch" id="clear-whitelist-button" data-setting="ClearWhitelistOn" data-parent="ImprovedPlaceManagement" />
<label class="form-check-label" for="clear-whitelist-button"> <span class="badge bg-primary mb-1">New in v1.3!</span> Quick Clear Whitelist Button </label>
</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>