console.log('path', window.location.pathname.split('/')[3]);
if (window.location.pathname.split('/')[3] === 'inventory') {
const Username = window.location.pathname.split('/')[2];
console.log(JSON.parse(window.localStorage.getItem('p+account_info')).Username);
if (Username === JSON.parse(window.localStorage.getItem('p+account_info')).Username) {
console.log('is user');
let Nav = document.getElementsByClassName('nav-pills')[0];
let WishlistNav = document.createElement('li');
WishlistNav.classList.add('nav-item');
WishlistNav.innerHTML = `
Item Wishlist
`;
Nav.appendChild(WishlistNav);
if (window.location.pathname.split('/')[4] === 'wishlist') {
console.log('aaa');
const ItemGrid = document.getElementsByClassName('itemgrid')[0];
const ItemCardContents = `
:ItemName
by :CreatorName
`;
Array.from(ItemGrid.children).forEach((element) => {
element.remove();
});
Array.from(Nav.children).forEach((element) => {
element = element.children[0];
if (!(element === WishlistNav)) {
if (element.classList.contains('active')) {
element.classList.remove('active');
}
}
});
WishlistNav.children[0].classList.add('active');
const Search = document.createElement('div');
Search.classList = 'row';
Search.innerHTML = `
`;
ItemGrid.parentElement.prepend(document.createElement('br'), ItemGrid.parentElement.children[0]);
ItemGrid.parentElement.prepend(Search, ItemGrid.parentElement.children[0]);
let Type = document.getElementById('polyplus-itemwish-type');
let SearchBar = document.getElementById('polyplus-itemwish-searchbar');
let IsLimited = document.getElementById('polyplus-itemwish-isLimited');
let IsAvailable = document.getElementById('polyplus-itemwish-isAvailable');
Type.addEventListener('change', function () {
Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked);
});
SearchBar.addEventListener('change', function () {
Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked);
});
IsLimited.addEventListener('change', function () {
Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked);
});
IsAvailable.addEventListener('change', function () {
Update(Type.options[Type.selectedIndex].value, SearchBar.value, IsLimited.checked, IsAvailable.checked);
});
chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function (result) {
let Wishlist = result.PolyPlus_ItemWishlist || [];
console.log('wishlist: ', Wishlist);
Wishlist.forEach((element) => {
let NewItemCard = document.createElement('div');
NewItemCard.classList = 'px-0';
fetch('https://api.polytoria.com/v1/store/:id'.replace(':id', element))
.then((response) => response.json())
.then((data) => {
NewItemCard.innerHTML = ItemCardContents.replace(':ItemID', data.id)
.replace(':ItemThumbnail', data.thumbnail)
.replace(':ItemName', data.name)
.replace(':CreatorID', data.creator.id)
.replace(':CreatorName', data.creator.name);
if (data.isLimited === true) {
NewItemCard.innerHTML = NewItemCard.innerHTML.replace(':LimitedTag', 'Limited
');
} else {
NewItemCard.innerHTML = NewItemCard.innerHTML.replace(':LimitedTag', '');
}
NewItemCard.setAttribute('data-id', data.id);
NewItemCard.setAttribute('data-name', data.name);
NewItemCard.setAttribute('data-type', data.type);
NewItemCard.setAttribute('data-creator', data.creator.name);
NewItemCard.setAttribute('data-limited', data.isLimited);
if (data.isLimited === false) {
NewItemCard.setAttribute('data-price', data.price);
}
ItemGrid.appendChild(NewItemCard);
NewItemCard.getElementsByClassName('polyplus-itemwish-removebtn')[0].addEventListener('click', function () {
let Index = Wishlist.indexOf(parseInt(NewItemCard.getAttribute('data-id')));
if (Index === -1) {
NewItemCard.remove();
return;
} else {
Wishlist.splice(Index, 1);
console.log(Wishlist);
NewItemCard.remove();
}
chrome.storage.sync.set({PolyPlus_ItemWishlist: Wishlist, arrayOrder: true}, function () {
console.log('ItemWishlist successfully saved: ' + ItemWishlist);
});
});
})
.catch((error) => {
console.error('Error:', error);
});
});
});
}
}
}
function Update(type, query, isLimited, isAvailable) {
let ItemGrid = document.getElementsByClassName('itemgrid')[0];
let BrickBalance = parseInt(JSON.parse(window.localStorage.getItem('p+account_info')).Bricks);
query = query.toLowerCase();
let Results = Array.from(ItemGrid.children);
for (let i = 0; i < Results.length; i++) {
let Show = true;
console.log('type: ', type);
if (!(type === 'any')) {
console.log("isn't any");
if (!(Results[i].getAttribute('data-type') === type)) {
Show = false;
}
}
if (!Results[i].getAttribute('data-name').toLowerCase().startsWith(query)) {
Show = false;
}
if (isLimited === true) {
if (!(Results[i].getAttribute('data-limited') === 'true')) {
Show = false;
}
}
if (isAvailable === true) {
if (!(parseInt(Results[i].getAttribute('data-price')) <= BrickBalance)) {
Show = false;
}
}
if (Show === true) {
Results[i].style.display = 'block';
} else {
Results[i].style.display = 'none';
}
}
}