feat: "pinned games" rewrite
This commit is contained in:
parent
90dab88d0e
commit
0eca6b62c7
2 changed files with 173 additions and 312 deletions
237
js/account/home.js
Executable file → Normal file
237
js/account/home.js
Executable file → Normal file
|
|
@ -1,194 +1,81 @@
|
||||||
/*
|
chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames'], async function(result){
|
||||||
this file needs a rewrite by me lol
|
Settings = result.PolyPlus_Settings || {
|
||||||
*/
|
PinnedGamesOn: true
|
||||||
|
|
||||||
var Settings;
|
|
||||||
var PinnedGamesData;
|
|
||||||
var BestFriendsData;
|
|
||||||
|
|
||||||
let Utilities;
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
|
||||||
Utilities = Utilities.default;
|
|
||||||
|
|
||||||
chrome.storage.sync.get(['PolyPlus_Settings'], async function (result) {
|
|
||||||
Settings = Utilities.MergeObjects(result.PolyPlus_Settings || Utilities.DefaultSettings);
|
|
||||||
|
|
||||||
if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
|
|
||||||
IRLPrice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.HomeFriendCountOn === true) {
|
if (Settings.PinnedGamesOn === true) {
|
||||||
ShowFriendCount();
|
const PlaceIDs = result.PolyPlus_PinnedGames || [];
|
||||||
|
|
||||||
|
const PinnedGamesContainer = document.createElement('div')
|
||||||
|
PinnedGamesContainer.innerHTML = `
|
||||||
|
<div class="row reqFadeAnim px-2 px-lg-0">
|
||||||
|
<div class="col">
|
||||||
|
<h6 class="dash-ctitle2">Jump right back into your favorite games</h6>
|
||||||
|
<h5 class="dash-ctitle">Pinned Games</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card card-dash mcard mb-3">
|
||||||
|
<div class="card-body p-0 m-1 scrollFadeContainer" id="p+pinned_games_card">
|
||||||
|
<div class="text-center p-5">
|
||||||
|
<div class="spinner-border text-muted" role="status">
|
||||||
|
<span class="visually-hidden">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
|
||||||
|
const RightSideColumn = document.getElementsByClassName('col-lg-8')[0];
|
||||||
|
if (document.getElementsByClassName('home-event-container')[0] === undefined) {
|
||||||
|
RightSideColumn.insertBefore(PinnedGamesContainer, RightSideColumn.children[0]);
|
||||||
|
} else {
|
||||||
|
RightSideColumn.insertBefore(PinnedGamesContainer, RightSideColumn.children[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.PinnedGamesOn === true || Settings.BestFriendsOn === true) {
|
const PinnedGamesCard = document.getElementById('p+pinned_games_card')
|
||||||
Update();
|
for (let i = 0; i < PlaceIDs.length; i++) {
|
||||||
}
|
const PlaceID = PlaceIDs.toSorted((a, b) => b - a)[i]
|
||||||
});
|
const PlaceDetails = (await (await fetch('https://api.polytoria.com/v1/places/' + PlaceID)).json())
|
||||||
})();
|
|
||||||
|
|
||||||
let ContainerElement = `
|
const PlaceCard = document.createElement('a')
|
||||||
<div class="card-body p-0 m-1 scrollFadeContainer d-flex"></div>`;
|
PlaceCard.classList = 'd-none'
|
||||||
let GameContainerElement = `
|
PlaceCard.href = '/places/' + PlaceID
|
||||||
|
PlaceCard.innerHTML = `
|
||||||
<div class="scrollFade card me-2 place-card force-desktop text-center mb-2" style="opacity: 1;">
|
<div class="scrollFade card me-2 place-card force-desktop text-center mb-2" style="opacity: 1;">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="ratings-header">
|
<div class="ratings-header">
|
||||||
<img src=":Thumbnail" class="place-card-image" style="position: relative;">
|
<img src="${PlaceDetails.thumbnail}" class="place-card-image" style="position: relative;">
|
||||||
<div style="position: absolute;background: linear-gradient(to bottom, black, transparent, transparent, transparent);width: 100%;height: 100%;top: 0;left: 0;border-radius: 10px;padding-top: 5px;color: gray;font-size: 0.8rem;">
|
<div class="p+pinned_games_playing" style="position: absolute;background: linear-gradient(to bottom, #000000f7, transparent, transparent, transparent);width: 100%;height: 100%;top: 0;left: 0;border-radius: 15px;padding-top: 12px;color: gray;font-size: 0.8rem;">
|
||||||
|
<i class="fa-duotone fa-users"></i>
|
||||||
<span>
|
<span>
|
||||||
<i id="thumbup-icn" class="thumb-icon far fa-thumbs-up"></i>
|
${PlaceDetails.playing}
|
||||||
:Likes
|
Playing
|
||||||
</span>
|
|
||||||
|
|
|
||||||
<span>
|
|
||||||
<i id="thumbdown-icn" class="thumb-icon far fa-thumbs-down"></i>
|
|
||||||
:Dislikes
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="mt-2 mb-1 place-card-title">
|
<div class="mt-2 mb-1 place-card-title">
|
||||||
:GameName
|
${PlaceDetails.name}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`
|
||||||
let TitleElement = `
|
|
||||||
<div class="col">
|
|
||||||
<h6 class="dash-ctitle2">Jump right back into your favorite games</h6>
|
|
||||||
<h5 class="dash-ctitle">Pinned Games</h5>
|
|
||||||
</div>`;
|
|
||||||
var FriendContainer = document.querySelector('.card:has(.friendsPopup) .card-body');
|
|
||||||
|
|
||||||
let NewContainer = document.createElement('div');
|
if (!PlaceDetails.isActive) {
|
||||||
NewContainer.style.display = 'none';
|
const PlayerCountText = PlaceCard.getElementsByClassName('p+pinned_games_playing')[0]
|
||||||
NewContainer.classList = 'card card-dash mcard mb-3';
|
PlayerCountText.children[0].classList = 'text-warning fa-duotone fa-lock'
|
||||||
NewContainer.style.animationDelay = '0.18s';
|
PlayerCountText.children[1].remove()
|
||||||
NewContainer.innerHTML = ContainerElement;
|
|
||||||
|
|
||||||
let NewTitle = document.createElement('div');
|
|
||||||
NewTitle.style.display = 'none';
|
|
||||||
NewTitle.classList = 'row reqFadeAnim px-2 px-lg-0';
|
|
||||||
NewTitle.innerHTML = TitleElement;
|
|
||||||
|
|
||||||
let BestFriendsContainer = document.createElement('div');
|
|
||||||
BestFriendsContainer.classList = 'd-flex';
|
|
||||||
BestFriendsContainer.style = 'display: none; border-bottom: 1px solid #000; padding-bottom: 10px; margin-bottom: 10px; width: 100%;';
|
|
||||||
|
|
||||||
let Spacer = document.createElement('div');
|
|
||||||
Spacer.innerHTML = ' ';
|
|
||||||
Spacer.style.width = '50px';
|
|
||||||
Spacer.prepend(BestFriendsContainer);
|
|
||||||
|
|
||||||
FriendContainer.prepend(BestFriendsContainer);
|
|
||||||
|
|
||||||
async function Update() {
|
|
||||||
chrome.storage.sync.get(['PolyPlus_PinnedGames'], function (result) {
|
|
||||||
PinnedGamesData = result.PolyPlus_PinnedGames.toSorted((a, b) => b - a) || [];
|
|
||||||
|
|
||||||
if (Settings.PinnedGamesOn === true) {
|
|
||||||
PinnedGames();
|
|
||||||
} else {
|
|
||||||
NewContainer.style.display = 'none';
|
|
||||||
NewTitle.style.display = 'none';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
chrome.storage.sync.get(['PolyPlus_BestFriends'], function (result) {
|
|
||||||
BestFriendsData = result.PolyPlus_BestFriends || [];
|
|
||||||
|
|
||||||
if (Settings.BestFriendsOn === true) {
|
|
||||||
BestFriends();
|
|
||||||
} else {
|
|
||||||
BestFriendsContainer.style.display = 'none';
|
|
||||||
Spacer.style.display = 'none';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function PinnedGames() {
|
PinnedGamesCard.appendChild(PlaceCard)
|
||||||
var Existing = NewContainer.children[0].children;
|
}
|
||||||
Array.from(Existing).forEach((element) => {
|
PinnedGamesCard.children[0].remove()
|
||||||
element.remove();
|
PinnedGamesCard.classList.add('d-flex')
|
||||||
});
|
Array.from(PinnedGamesCard.children).forEach((place) => {place.classList.remove('d-none')})
|
||||||
|
|
||||||
if (PinnedGamesData.length === 0) {
|
|
||||||
NewContainer.style.display = 'none';
|
|
||||||
NewTitle.style.display = 'none';
|
|
||||||
} else {
|
|
||||||
NewContainer.style.display = '';
|
|
||||||
NewTitle.style.display = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let element of PinnedGamesData) {
|
if (Settings.IRLPriceWithCurrency && Settings.IRLPriceWithCurrency.Enabled === true) {
|
||||||
fetch('https://api.polytoria.com/v1/places/' + element)
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
let GameName = data.name;
|
|
||||||
let GameThumbnail = data.thumbnail;
|
|
||||||
|
|
||||||
var NewGameContainer = document.createElement('a');
|
|
||||||
NewGameContainer.innerHTML = GameContainerElement.replace(':GameName', GameName)
|
|
||||||
.replace(':Thumbnail', GameThumbnail)
|
|
||||||
.replace(':Likes', data.rating.likes)
|
|
||||||
.replace(':Dislikes', data.rating.dislikes);
|
|
||||||
NewGameContainer.href = '/places/' + element;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (new Date().getDate() >= new Date(data.updatedAt).getDate()) {
|
|
||||||
console.log('Game has updated')
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
NewContainer.children[0].appendChild(NewGameContainer);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function BestFriends() {
|
|
||||||
return
|
|
||||||
Array.from(document.querySelectorAll('[bestFriend]')).forEach((element) => {
|
|
||||||
element.removeAttribute('bestFriend');
|
|
||||||
element.getElementsByClassName('friend-name')[0].style.color = 'initial';
|
|
||||||
FriendContainer.appendChild(element);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (BestFriendsData.length === 0) {
|
|
||||||
BestFriendsContainer.style.visibility = 'hidden';
|
|
||||||
BestFriendsContainer.style.padding = '0px !important';
|
|
||||||
BestFriendsContainer.style.margin = '0px !important';
|
|
||||||
} else {
|
|
||||||
BestFriendsContainer.style.visibility = 'visible';
|
|
||||||
BestFriendsContainer.style.padding = '';
|
|
||||||
BestFriendsContainer.style.margin = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
BestFriendsData.forEach((element) => {
|
|
||||||
let ExistingFriend = document.getElementById('friend-' + element);
|
|
||||||
if (ExistingFriend) {
|
|
||||||
ExistingFriend.setAttribute('bestFriend', 'true');
|
|
||||||
ExistingFriend.getElementsByClassName('friend-name')[0].style.color = 'yellow';
|
|
||||||
BestFriendsContainer.prepend(ExistingFriend);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var SecondaryColumn = document.getElementsByClassName('col-lg-8')[0];
|
|
||||||
if (document.getElementsByClassName('home-event-container')[0] === undefined) {
|
|
||||||
SecondaryColumn.insertBefore(NewContainer, SecondaryColumn.children[0]);
|
|
||||||
SecondaryColumn.insertBefore(NewTitle, SecondaryColumn.children[0]);
|
|
||||||
} else {
|
|
||||||
SecondaryColumn.insertBefore(NewContainer, SecondaryColumn.children[1]);
|
|
||||||
SecondaryColumn.insertBefore(NewTitle, SecondaryColumn.children[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function IRLPrice() {
|
|
||||||
(async () => {
|
(async () => {
|
||||||
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
Utilities = await import(chrome.runtime.getURL('resources/utils.js'));
|
||||||
Utilities = Utilities.default;
|
Utilities = Utilities.default;
|
||||||
|
|
@ -209,17 +96,8 @@ async function IRLPrice() {
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ShowFriendCount() {
|
if (Settings.HomeFriendCountOn === true) {
|
||||||
let FriendCount = (await (await fetch('https://polytoria.com/api/friends?page=1')).json()).meta.total;
|
const FriendCount = (await (await fetch('https://polytoria.com/api/friends?page=1')).json()).meta.total;
|
||||||
/*
|
|
||||||
const FirstPage = (await (await fetch('https://polytoria.com/api/friends?page=1')).json())
|
|
||||||
if (FirstPage.meta.lastPage > 1) {
|
|
||||||
const LastPage = (await (await fetch('https://polytoria.com/api/friends?page=' + Pages)).json())
|
|
||||||
FriendCount = (12*(FirstPage.meta.pages-1)) + LastPage.data.length
|
|
||||||
} else {
|
|
||||||
FriendCount = FirstPage.data.length
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const CountText = document.createElement('small');
|
const CountText = document.createElement('small');
|
||||||
CountText.classList = 'text-muted fw-lighter';
|
CountText.classList = 'text-muted fw-lighter';
|
||||||
|
|
@ -227,3 +105,4 @@ async function ShowFriendCount() {
|
||||||
CountText.innerText = ' (' + FriendCount + ')';
|
CountText.innerText = ' (' + FriendCount + ')';
|
||||||
document.querySelector('#home-friendsOnline h5').appendChild(CountText);
|
document.querySelector('#home-friendsOnline h5').appendChild(CountText);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const PlaceID = window.location.pathname.split('/')[2];
|
const PlaceID = parseInt(window.location.pathname.split('/')[2]);
|
||||||
const UserID = JSON.parse(window.localStorage.getItem('p+account_info')).ID;
|
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];
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
||||||
|
|
||||||
RatingsContainer.children[0].appendChild(PercentageLabel);
|
RatingsContainer.children[0].appendChild(PercentageLabel);
|
||||||
|
|
||||||
chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_TimePlayed'], async function (result) {
|
chrome.storage.sync.get(['PolyPlus_Settings', 'PolyPlus_PinnedGames', 'PolyPlus_TimePlayed'], async function (result) {
|
||||||
Settings = result.PolyPlus_Settings || {};
|
Settings = result.PolyPlus_Settings || {};
|
||||||
TimePlayed = result.PolyPlus_TimePlayed || {};
|
TimePlayed = result.PolyPlus_TimePlayed || {};
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
||||||
Utilities = Utilities.default;
|
Utilities = Utilities.default;
|
||||||
|
|
||||||
if (Settings.PinnedGamesOn === true) {
|
if (Settings.PinnedGamesOn === true) {
|
||||||
PinnedGames();
|
PinnedGames(result.PolyPlus_PinnedGames);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.InlineEditingOn === true && GameCreator === UserID) {
|
if (Settings.InlineEditingOn === true && GameCreator === UserID) {
|
||||||
|
|
@ -127,7 +127,6 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.ImprovedAchievements.OpacityOn && Settings.ImprovedAchievements.OpacityOn === true) {
|
if (Settings.ImprovedAchievements.OpacityOn && Settings.ImprovedAchievements.OpacityOn === true) {
|
||||||
console.log(Settings)
|
|
||||||
for (let achievement of Achievements) {
|
for (let achievement of Achievements) {
|
||||||
if ((achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) === false) {
|
if ((achievement.getElementsByClassName('fad fa-check-circle')[0] !== undefined) === false) {
|
||||||
achievement.style.opacity = '0.5';
|
achievement.style.opacity = '0.5';
|
||||||
|
|
@ -142,94 +141,76 @@ const Gamepasses = Array.from(GamepassesTab.getElementsByClassName('card')) || [
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function PinnedGames() {
|
function PinnedGames(placeIDs) {
|
||||||
chrome.storage.sync.get(['PolyPlus_PinnedGames'], function (result) {
|
const PinButton = document.createElement('button')
|
||||||
PinnedGamesData = result.PolyPlus_PinnedGames || [];
|
PinButton.classList = 'btn btn-primary btn-sm'
|
||||||
|
PinButton.style = 'position: absolute; top: 0; right: 0; margin: 4px; font-size: 1.3em;'
|
||||||
|
PinButton.innerHTML = `
|
||||||
|
<i class="fa-regular fa-star"></i>
|
||||||
|
`
|
||||||
|
|
||||||
const PinBtn = document.createElement('button');
|
const UpdatePinButtonState = function(){
|
||||||
PinBtn.classList = 'btn btn-warning btn-sm';
|
PinButton.classList = 'btn btn-primary btn-sm'
|
||||||
PinBtn.style = 'position: absolute; right: 0; margin-right: 7px;';
|
if (placeIDs.indexOf(PlaceID) === -1) {
|
||||||
|
// Not Pinned
|
||||||
if (PinnedGamesData.includes(parseInt(PlaceID))) {
|
if (placeIDs.length >= Utilities.Limits.PinnedGames) {
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Un-pin';
|
PinButton.disabled = true
|
||||||
|
}
|
||||||
|
PinButton.children[0].classList = 'fa-regular fa-star'
|
||||||
} else {
|
} else {
|
||||||
if (PinnedGamesData.length !== Utilities.Limits.PinnedGames) {
|
// Pinned
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin';
|
PinButton.children[0].classList = 'fa-duotone fa-star'
|
||||||
} else {
|
|
||||||
PinBtn.setAttribute('disabled', true);
|
|
||||||
PinBtn.innerHTML = `<i class="fa-duotone fa-star"></i> Pin (max ${Utilities.Limits.PinnedGames}/${Utilities.Limits.PinnedGames})`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PinBtn.addEventListener('click', function () {
|
PinButton.addEventListener('mouseenter', function(){
|
||||||
PinBtn.setAttribute('disabled', 'true');
|
if (placeIDs.indexOf(PlaceID) !== -1) {
|
||||||
|
PinButton.classList.add('btn-danger')
|
||||||
chrome.storage.sync.get(['PolyPlus_PinnedGames'], function (result) {
|
PinButton.classList.remove('btn-primary')
|
||||||
PinnedGamesData = result.PolyPlus_PinnedGames || [];
|
PinButton.children[0].classList.add('fa-star-half-stroke')
|
||||||
/*
|
PinButton.children[0].classList.remove('fa-star')
|
||||||
const Index = PinnedGames.indexOf(parseInt(PlaceID))
|
|
||||||
if (Index !== -1) {
|
|
||||||
//delete PinnedGames[PlaceID]
|
|
||||||
PinnedGames.splice(Index, 1)
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin'
|
|
||||||
} else {
|
|
||||||
//PinnedGames[PlaceID] = {lastVisited: new Date()}
|
|
||||||
PinnedGames.push(parseInt(PlaceID))
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Un-pin'
|
|
||||||
}
|
}
|
||||||
*/
|
})
|
||||||
const Index = PinnedGamesData.indexOf(parseInt(PlaceID));
|
|
||||||
if (Index !== -1) {
|
PinButton.addEventListener('mouseleave', function(){
|
||||||
PinnedGamesData.splice(Index, 1);
|
if (placeIDs.indexOf(PlaceID) !== -1) {
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin';
|
PinButton.classList.add('btn-primary')
|
||||||
} else {
|
PinButton.classList.remove('btn-danger')
|
||||||
PinnedGamesData.push(parseInt(PlaceID));
|
PinButton.children[0].classList.add('fa-star')
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Un-pin';
|
PinButton.children[0].classList.remove('fa-star-half-stroke')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
UpdatePinButtonState()
|
||||||
|
document.querySelector('h1.my-0').parentElement.appendChild(PinButton)
|
||||||
|
|
||||||
|
PinButton.addEventListener('click', function(){
|
||||||
|
if (placeIDs.length >= Utilities.Limits.PinnedGames) {
|
||||||
|
PinButton.disabled = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.storage.sync.set({PolyPlus_PinnedGames: PinnedGamesData, arrayOrder: true}, function () {
|
if (placeIDs.indexOf(PlaceID) === -1) {
|
||||||
setTimeout(function () {
|
placeIDs.push(PlaceID)
|
||||||
PinBtn.removeAttribute('disabled');
|
} else {
|
||||||
console.log(PinnedGamesData);
|
placeIDs.splice(placeIDs.indexOf(PlaceID), 1)
|
||||||
}, 1250);
|
}
|
||||||
});
|
|
||||||
});
|
PinButton.disabled = true
|
||||||
|
UpdatePinButtonState()
|
||||||
|
|
||||||
|
chrome.storage.sync.set({'PolyPlus_PinnedGames': placeIDs}, function(){
|
||||||
|
setTimeout(() => {
|
||||||
|
PinButton.disabled = false
|
||||||
|
}, 750);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementsByClassName('card-header')[2].appendChild(PinBtn);
|
chrome.storage.onChanged.addListener(function (changes) {
|
||||||
|
|
||||||
chrome.storage.onChanged.addListener(function (changes, namespace) {
|
|
||||||
if ('PolyPlus_PinnedGames' in changes) {
|
if ('PolyPlus_PinnedGames' in changes) {
|
||||||
chrome.storage.sync.get(['PolyPlus_PinnedGames'], function (result) {
|
placeIDs = changes.PolyPlus_PinnedGames.newValue
|
||||||
PinnedGamesData = result.PolyPlus_PinnedGames || [];
|
UpdatePinButtonState()
|
||||||
|
|
||||||
/*
|
|
||||||
if (PinnedGamesData[PlaceID]) {
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Un-pin'
|
|
||||||
} else {
|
|
||||||
if (PinnedGamesData.length !== 5) {
|
|
||||||
PinBtn.removeAttribute('disabled')
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin'
|
|
||||||
} else {
|
|
||||||
PinBtn.setAttribute('disabled', true)
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin (max 5/5)'
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (PinnedGamesData.includes(parseInt(PlaceID))) {
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Un-pin';
|
|
||||||
} else {
|
|
||||||
if (PinnedGamesData.length !== Utilities.Limits.PinnedGames) {
|
|
||||||
PinBtn.removeAttribute('disabled');
|
|
||||||
PinBtn.innerHTML = '<i class="fa-duotone fa-star"></i> Pin';
|
|
||||||
} else {
|
|
||||||
PinBtn.setAttribute('disabled', true);
|
|
||||||
PinBtn.innerHTML = `<i class="fa-duotone fa-star"></i> Pin (max ${Utilities.Limits.PinnedGames}/${Utilities.Limits.PinnedGames})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -547,6 +528,7 @@ async function ReaddCopyable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlaceDetails.isCopyable) {
|
if (PlaceDetails.isCopyable) {
|
||||||
|
console.log('is copyable')
|
||||||
const TitleCardButtons = document.querySelector('.card:has(h1.my-0) .col-auto[style^="m"]')
|
const TitleCardButtons = document.querySelector('.card:has(h1.my-0) .col-auto[style^="m"]')
|
||||||
|
|
||||||
const DownloadCopyButton = document.createElement('button')
|
const DownloadCopyButton = document.createElement('button')
|
||||||
|
|
|
||||||
Reference in a new issue