This repository has been archived on 2026-01-04. You can view files and clone it, but cannot push or open issues or pull requests.
polyplus/js/store/item-view.js
Index 251e28edeb Update Notification Banner & Improvements
- Update banner on settings page with 2 options: go to releases page on this GitHub repository or to skip this update (unrecommended)

- You can now skip updates (again, unrecommended)

- Added "Reset to Default" button on all options modals on the settings page which will reset that setting's specific options to their defaults.

- Removed element IDs from the "Modify Navbar" feature options modal (they were there due to the old way options modals worked before release)

- Renamed polyplus-settings.js to settings.js

- Updated all "IRL Price with Brick Count" display code to have different variable names

- "IRL Price with Brick Count" is more accurate by parsing abbreviated numbers into their full number (fixing odd bugs that would happen with things such as a user's networth) - it is still not super accurate when it comes to users' networth but it's way better than before

 - You can now clear specific data locations (chrome.storage.sync and chrome.storage.local) on the extension's debug page

- Updated update notifier code

- The profile page now uses the utilities to calculate the "IRL Price with Brick Count" result rather than using the old repetitive code

- Added another extension icon for when the extension has an update available - it currently isn't used anywhere due to the code for it not working for some reason
2024-03-07 10:38:11 -06:00

139 lines
No EOL
5 KiB
JavaScript
Executable file

const ItemID = window.location.pathname.split('/')[2]
const ItemType = document.querySelector('.col-12 .badge').innerHTML
var Utilities;
var Settings;
var ItemWishlist;
var PurchaseBtn;
var WishlistBtn;
var ItemOwned;
(async () => {
if (!(window.location.href.split('/')[4]) || ItemType === "achievement") {return}
Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
chrome.storage.sync.get(['PolyPlus_Settings'], function(result){
Settings = result.PolyPlus_Settings || {}
PurchaseBtn = document.querySelector('.btn#purchase-button')
if (ItemType === "gamePass") {
PurchaseBtn = document.querySelector('.btn.btn-outline-success[onclick^="buyAsset"]')
}
ItemOwned = (PurchaseBtn.innerText === ' Item owned' || document.querySelector('.btn[onclick="sellItem()"]') !== null)
if (Settings.IRLPriceWithCurrencyOn === true) { IRLPrice() }
if (Settings.ItemWishlistOn === true) {
HandleItemWishlist()
}
})
})();
chrome.storage.onChanged.addListener(function(changes, namespace) {
if ('PolyPlus_ItemWishlist' in changes) {
chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result) {
ItemWishlist = result.PolyPlus_ItemWishlist || [];
if (Array.isArray(ItemWishlist) && ItemWishlist.includes(parseInt(ItemID))) {
WishlistBtn.classList = 'btn btn-danger btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Un-Wishlist Item
`
} else {
if (!(ItemWishlist.length === 25)) {
WishlistBtn.removeAttribute('disabled')
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
} else {
WishlistBtn.setAttribute('disabled', true)
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
}
}
});
}
});
async function IRLPrice() {
if (!(PurchaseBtn.getAttribute('disabled'))) {
const Price = PurchaseBtn.getAttribute('data-price')
const Span = document.createElement('span')
Span.classList = 'text-muted polyplus-own-tag'
Span.style.fontSize = '0.7rem'
Span.style.fontWeight = 'normal'
const IRLResult = await Utilities.CalculateIRL(Price, Settings.IRLPriceWithCurrencyCurrency)
Span.innerText = "($" + IRLResult.result + " " + IRLResult.display + ")"
PurchaseBtn.appendChild(Span)
}
}
function HandleItemWishlist() {
const DescriptionText = document.querySelector('.mcard .card-body:has(p)')
WishlistBtn = document.createElement('button')
chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){
ItemWishlist = result.PolyPlus_ItemWishlist || [];
if (ItemOwned === true) {
if (ItemWishlist.includes(parseInt(ItemID))) {
ItemWishlist.splice(ItemWishlist.indexOf(parseInt(ItemID)), 1)
chrome.storage.sync.set({'PolyPlus_ItemWishlist': ItemWishlist, arrayOrder: true});
}
return
}
if (ItemOwned === true) {
return
} else if (ItemOwned === true && ItemWishlist.includes(parseInt(ItemID))) {
ItemWishlist.splice(ItemWishlist.indexOf(parseInt(ItemID)), 1)
return
}
if (ItemWishlist.includes(parseInt(ItemID))) {
WishlistBtn.classList = 'btn btn-danger btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Un-Wishlist Item
`
} else {
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
}
WishlistBtn.addEventListener('click', function(){
WishlistBtn.setAttribute('disabled', true)
chrome.storage.sync.get(['PolyPlus_ItemWishlist'], function(result){
ItemWishlist = result.PolyPlus_ItemWishlist || [];
let i = ItemWishlist.indexOf(parseInt(ItemID))
if (i !== -1) {
ItemWishlist.splice(i, 1)
WishlistBtn.classList = 'btn btn-primary btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Wishlist Item
`
} else {
ItemWishlist.push(parseInt(ItemID))
WishlistBtn.classList = 'btn btn-danger btn-sm'
WishlistBtn.innerHTML = `
<i class="fa fa-star" style="margin-right: 2.5px;"></i> Un-Wishlist Item
`
}
chrome.storage.sync.set({'PolyPlus_ItemWishlist': ItemWishlist, arrayOrder: true}, function() {
setTimeout(function() {
WishlistBtn.removeAttribute('disabled')
}, 1250)
});
});
});
DescriptionText.appendChild(document.createElement('br'))
DescriptionText.appendChild(WishlistBtn)
});
}