import "@/public/css/specific.css";
import config from "@/utils/config.json";
import { bricksToCurrency } from "@/utils/utilities";
import { userDetails } from "@/utils/types";
import * as apiTypes from "@/utils/api/types";
import { getAPI } from "@/utils/api";
const itemID = window.location.pathname.split("/")[2];
/**
* Adds the locale real-life dollar value next to the amount of bricks an item costs in the text of the purchase button.
*/
export function irlBrickPrice() {
try {
const purchaseBtn = document.querySelector(
'button[onclick^="buy"], button[data-price]',
)!;
const currency = bricksToCurrency(
parseInt(purchaseBtn.getAttribute("data-price")!),
"USD",
);
if (currency) {
const spanTag = document.createElement("span");
spanTag.classList.add("text-muted");
spanTag.style.fontSize = "0.7rem";
spanTag.style.fontWeight = "lighter";
spanTag.innerText = ` (${currency})`;
purchaseBtn.appendChild(spanTag);
}
} catch (e) {
// The store purchase button has several different ways of being represented, this should
// only happen when the item is already owned
console.warn("[Poly+] Failure to find purchase button on page.");
}
const addPrice = function (item: HTMLElement) {
const price = item.getElementsByClassName("text-success")[0];
const purchaseBtn = item.querySelector("button[data-listing-id]");
if (price && purchaseBtn) {
const currency = bricksToCurrency(
parseInt(purchaseBtn.getAttribute("data-price")!),
"USD",
);
if (currency) {
const spanTag = document.createElement("span");
spanTag.classList.add("text-muted");
spanTag.style.fontSize = "0.7rem";
spanTag.style.fontWeight = "lighter";
spanTag.innerText = ` (${currency})`;
price.appendChild(spanTag);
}
}
};
const resellers = document.getElementById("resellers-container");
if (resellers) {
for (const reseller of resellers.children) {
addPrice(reseller as HTMLElement);
}
const mutations = new MutationObserver((mutations) => {
for (const record of mutations) {
for (const node of record.addedNodes) {
addPrice(node as HTMLElement);
}
}
});
mutations.observe(resellers, { childList: true });
}
}
/**
* Adds a button below the item thumbnail preview allowing the user to preview their avatar with the item they are looking at equipped.
* @param user The public-facing details of the authenticated user.
*/
export function tryOn(user: userDetails) {
const publicAPI = getAPI("public");
const itemId = window.location.pathname.split("/")[2];
const favoriteBtn = document.querySelector(
'button[onclick^="toggleFavorite"]',
)!;
const button = document.createElement("button");
button.classList.add("btn", "btn-outline-primary", "btn-sm", "mt-2");
button.style.width = "50px";
button.innerHTML = '';
const modal = document.createElement("dialog");
modal.classList.add("polyplus-modal");
Object.assign(modal.style, {
width: "450px",
height: "500px",
border: "1px solid #484848",
backgroundColor: "#181818",
borderRadius: "20px",
overflow: "hidden",
});
modal.innerHTML = `
Sorry! This feature is currently unavailable. Please check back later!