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/resources/utils.js
Index eeaafeb35a Updates and Bug Fixes
- Experimental Feature: Event Items Store Category

- Fixed "Try On" store items

- Deleted "Try On" store items code and moved it to the main item view page script

- Fixed Transactions page Bricks to IRL Price converter

- Transactions page bricks to IRL Price converter now doesn't say "$NaN" when the input is erased

- Deleted popup and installation HTML files as they aren't used and haven't been used for a while. I am thinking of adding a new popup when you click the extension icon in your browser toolbar but that will be different than the code that was there.

- New Feature: Show "Owners" instead of "Sales"

- Updated theme code to run on all pages, even when the "Theme Creator" feature is turned off so that CSS such as modal CSS can still apply without other scripts having to apply their own CSS blob to the page

- Updated context menu background code to remove all context menus created by the extension before creating the context menus so the error for duplicate context menu IDs won't keep appearing (hopefully, but I haven't gotten the error yet so...)

- Fixed "Trending Items" IRL Brick price breaking if any of the trending items are free

- Improved detection for the purchase button on item view pages

- Fixed the item view page not checking if the item isn't owned before trying to add the IRL Brick price

- Removed old setTimeout() code at the start of some files
2024-04-20 11:58:00 -05:00

145 lines
3.3 KiB
JavaScript

/*
HOW TO USE IN CONTENT SCRIPTS:
(async () => {
let Utilities = await import(chrome.runtime.getURL('/js/resources/utils.js'));
Utilities = Utilities.default
})();
*/
function ParseFullNumber(ab) {
if (typeof(ab) === "number") { return ab }
const Suffixes = {"k": 1000, "m": 1000000, "b": 1000000000}
const Suffix = ab.slice(-1).toLowerCase();
if (Suffixes[Suffix]) {return parseFloat(ab)*Suffixes[Suffix]} else {return parseFloat(ab)}
}
export default {
DefaultSettings: {
PinnedGamesOn: true,
ForumMentsOn: true,
BestFriendsOn: false,
ImprovedFrListsOn: false,
IRLPriceWithCurrencyOn: true,
IRLPriceWithCurrencyCurrency: 0,
IRLPriceWithCurrencyPackage: 0,
HideNotifBadgesOn: false,
StoreOwnTagOn: true,
ThemeCreatorOn: false,
ThemeCreator: {
BGColor: null,
BGImage: null,
BGImageSize: 'fit',
PrimaryTextColor: null,
SecondaryTextColor: null,
LinkTextColor: null,
WebsiteLogo: null
},
ModifyNavOn: false,
ModifyNav: [
{
Label: "Play",
Link: "https://polytoria.com/places"
},
{
Label: "Store",
Link: "https://polytoria.com/store"
},
{
Label: "Guilds",
Link: "https://polytoria.com/guilds"
},
{
Label: "People",
Link: "https://polytoria.com/users"
},
{
Label: "Forum",
Link: "https://polytoria.com/forum"
}
],
MoreSearchFiltersOn: true,
ApplyMembershipThemeOn: false,
ApplyMembershipThemeTheme: 0,
MultiCancelOutTradesOn: true,
ItemWishlistOn: true,
HideUpgradeBtnOn: false,
TryOnItemsOn: true,
OutfitCostOn: true,
ShowPlaceRevenueOn: true,
ReplaceItemSalesOn: false
},
CalculateIRL: async function(bricks, to, brickPackage) {
/*
Disabled for now: currency retrieval from currencies.json
const response = await fetch(chrome.runtime.getURL('/js/resources/currencies.json'))
if (!response.ok) {
throw new Error('Getting currency data failure')
}
const data = await response.json()
const UnitPrice = data.Data[brickPackage][to]
*/
let Result = "N/A";
let Display = "Currency Not Found";
bricks = ParseFullNumber(bricks.replace(/,/g, ''))
switch (to) {
// U.S. Dollar
case 0:
Result = (bricks * 0.0099).toFixed(2)
Display = "USD"
break
// Euro
case 1:
Result = (bricks * 0.009).toFixed(2)
Display = "EUR"
break
// Canadian Dollar
case 2:
Result = (bricks * 0.0131).toFixed(2)
Display = "CAD"
break
// Great British Pound
case 3:
Result = (bricks * 0.0077).toFixed(2)
Display = "GBP"
break
// Mexican Peso
case 4:
Result = (bricks * 0.1691).toFixed(2)
Display = "MXN"
break
// Australia Dollar
case 5:
Result = (bricks * 0.0144).toFixed(2)
Display = "AUD"
break
// Turkish Lira
case 6:
Result = (bricks * 0.2338).toFixed(2)
Display = "TRY"
break
// Brazillian Real
case 7:
Result = (bricks * 0.49).toFixed(2)
Display = "BRL"
break
}
if (typeof(Result) === "number") { Result = Result.toFixed(2) }
return {
result: Result,
display: Display
}
}
}