You've already forked tf2wikipricing
37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
import { ItemPriceData } from "./priceService";
|
|
import { formatPrice } from "./utils/formatting";
|
|
import { $T } from "./utils/localization";
|
|
|
|
export function createPriceRow(qualityName: string, data: ItemPriceData, keyPrice: ItemPriceData, locale: string, wikiPage: string = null): HTMLTableRowElement {
|
|
const priceRow = document.createElement("tr");
|
|
|
|
const priceLabel = document.createElement("td");
|
|
priceLabel.className = "infobox-label";
|
|
const priceLabelLink = document.createElement("a");
|
|
if (wikiPage == null) {
|
|
wikiPage = `https://wiki.teamfortress.com/wiki/${qualityName}`
|
|
}
|
|
priceLabelLink.href = locale === 'en' ? wikiPage : `${wikiPage}/${locale}`
|
|
priceLabelLink.innerText = $T(qualityName)
|
|
priceLabel.appendChild(priceLabelLink);
|
|
priceLabel.innerHTML += ':'
|
|
priceRow.appendChild(priceLabel);
|
|
|
|
const priceData = document.createElement("td");
|
|
const priceLink = document.createElement("span");
|
|
const priceString = data ? formatPrice(data.keys, data.metal, keyPrice.metal, locale).trim() : $T('Data unavailable')
|
|
priceLink.innerHTML = priceString // + `<br>$${data.scmPrice}`
|
|
priceData.appendChild(priceLink);
|
|
priceRow.appendChild(priceData);
|
|
return priceRow;
|
|
}
|
|
|
|
export function createStoreButton(storeName: string, url: URL) {
|
|
const button = document.createElement("tr")
|
|
var source = `<td colspan="2" class="infobox-data" style="text-align:center"><div class="plainlinks btn_wrapper" style="width:100%"><a rel="nofollow" class="external text" href="{link}" target="_blank"><span class="btn_buynow_addon_${storeName.replaceAll('.', '')}">{title}<span></span></span></a></div></td>`
|
|
source = source.replace("{link}", url.toString())
|
|
source = source.replace("{title}", $T("View listings on %@").replace('%@', storeName))
|
|
button.innerHTML = source
|
|
return button
|
|
}
|