feat: "Homepage Join Friends Tooltip Button" feature

This commit is contained in:
Index 2024-07-16 22:26:11 -05:00
parent ffcb35d15f
commit f0ac985c13
2 changed files with 56 additions and 0 deletions

View file

@ -105,4 +105,45 @@ chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames'], async fun
CountText.innerText = ' (' + FriendCount + ')';
document.querySelector('#home-friendsOnline h5').appendChild(CountText);
}
if (Settings.HomeJoinFriendsButtonOn === true) {
const FriendsPopup = document.getElementById('friend-name')
const ChangeMutator = new MutationObserver(async function (list) {
for (let record of list) {
for (let node of record.addedNodes) {
if (node.tagName === 'A') {
const JoinButton = document.createElement('button')
JoinButton.classList = 'btn btn-success btn-sm'
JoinButton.style = 'position: absolute; top: 0; right: 0; z-index: 2000; font-size: 1.2rem;'
JoinButton.innerHTML = '<i class="fas fa-play"></i>'
node.parentElement.appendChild(JoinButton)
JoinButton.addEventListener('click', async function(){
const PlayingStatus = (await (await fetch('https://api.polytoria.com/v1/users/' + document.getElementById('friendsProfileLink').getAttribute('href').split('/')[2])).json()).playing;
const Token = (await (await fetch('https://polytoria.com/api/places/join', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
placeID: parseInt(node.getAttribute('href').split('/')[2]),
serverID: PlayingStatus.serverID
})
})).json())
if (!Token.success) {
alert(Token.message);
return
}
window.location.href = 'polytoria://client/' + Token.token
})
}
}
}
})
ChangeMutator.observe(FriendsPopup, {childList: true})
}
})

View file

@ -795,6 +795,21 @@
* Past playtime data (prior to extension install/prior to setting enable) is, understandably, not able to be tracked
</span>
</div>
<div class="setting-container" id="home-join-friends">
<span class="badge bg-primary mb-1">New in v1.3!</span>
<br>
<span class="indicator">&nbsp;</span>
<span class="title">
Homepage Join Friends Tooltip Button
</span>
<div class="setting-buttons">
<button class="btn btn-sm toggle-btn" data-setting="HomeJoinFriendsButtonOn">Toggle</button>
</div>
<br />
<span class="desc">
Quickly join your friends' servers by clicking the play button inside the tooltip in the "Friends" section of the homepage.
</span>
</div>
<!---
<div class="setting-container" id="auto-ad-bidding">
<span class="indicator">&nbsp;</span>