Skip to content

Commit

Permalink
add "oneClickOrder" feature for Skinport (#36)
Browse files Browse the repository at this point in the history
* feat: oneClickOrder

* feat: oneClickOrder

* Extension setting for Skinport's OneClickBuy

* Reworked OCO Error popup

* Adjust OCO error message design

* Skinport OCO CSRF caching

* OCO Cart checking + code cleanup

* Bugfix: add missing await for csrf caching

* Limit OCO on item prices < 2

* Dynamic min order price

* fix: merge issue

---------

Co-authored-by: GODrums <armin.stanitzok@outlook.de>
Co-authored-by: Armin <21990230+GODrums@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 21, 2023
1 parent 9361724 commit 9438ae9
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 3 deletions.
19 changes: 19 additions & 0 deletions css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ input[type='checkbox'] {
margin-right: 15px;
}

input[type='text'] {
width: 150px;
height: 30px;
border-radius: 5px;
margin-right: 15px;
background: var(--color-background, #303030);
border: 0;
color: white;
}

input[type="color"] {
width: 23px;
height: 23px;
Expand Down Expand Up @@ -395,6 +405,15 @@ input[type="color"]::-webkit-color-swatch-wrapper {
}
}

.LabelNew {
background: var(--color-accent, #ff5722);
border-radius: 5px;
padding: 3px 7px;
color: white;
font-size: 12px;
margin-left: 5px;
}

@keyframes rotating {
from {
-ms-transform: rotate(0deg);
Expand Down
49 changes: 49 additions & 0 deletions css/skinport_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,53 @@

.betterfloat-filterpopup-content {
margin: 10px 20px;
}

.BetterFloat-OCO-Message {
bottom: 8px;
left: 8px;
position: fixed;
z-index: 100;
}

.BetterFloat-OCO-Message .Message {
animation: shakeMessage 1s .2s;
background-color: #fff;
border-radius: 2.5px;
box-shadow: 0 10px 40px #1d2021;
color: #1d2021;
display: flex;
flex-direction: column;
max-width: 330px;
padding: 16px 20px 23px;
position: relative;
}

.BetterFloat-OCO-Message .Message--error .Message-title {
color: #fa490a;
font-size: 14px;
font-weight: 700;
margin-bottom: 7px;
}

.BetterFloat-OCO-Message .Message-text {
font-size: 12px;
line-height: 18px;
margin-bottom: 14px;
}

.BetterFloat-OCO-Message .Message-buttons {
display: flex;
}

.BetterFloat-OCO-Message .Message-closeBtn {
color: #4db5da;
font-size: 12px;
font-weight: 700;
letter-spacing: 1.6px;
margin-right: 0;
outline: none;
position: relative;
text-transform: uppercase;
transition: color .2s ease;
}
14 changes: 14 additions & 0 deletions html/skinport.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
</div>
<div class="Group">
<div class="GroupHeader">MISC</div>
<div class="GroupElement">
<div class="GroupElementExtended">
<div class="GroupRow">
<div style="display: flex; align-items: center; gap: 4px;">
<p class="ElementText">OneClickBuy</p>
<span class="LabelNew">NEW</span>
</div>
<input type="text" id="InputOneClickBuy" name="ocoAPIKey" />
</div>
<p class="ElementDescription" style="padding-bottom: 0;">
Enter your API-key for the OneClickBuy-feature. Leave empty to disable.<br /> A valid key can be generated on the BetterFloat Discord server.
</p>
</div>
</div>
<div class="GroupElementExtended">
<div class="GroupRow">
<p class="ElementText">Buff Link Position</p>
Expand Down
1 change: 1 addition & 0 deletions src/@typings/ExtensionTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export namespace Extension {
spCheckBoxes: boolean;
spStickerPrices: boolean;
spBlueGem: boolean;
ocoAPIKey: string;
spPriceReference: 0 | 1;
spSteamPrice: boolean;
spBuffDifference: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const defaultSettings: Extension.Settings = {
spCheckBoxes: true,
spStickerPrices: true,
spBlueGem: true,
ocoAPIKey: '',
spPriceReference: 0,
skinportRates: 'real',
spSteamPrice: false,
Expand Down
2 changes: 1 addition & 1 deletion src/csfloat/content_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ async function webDetection(container: Element, item: CSFloat.Item) {
// add replacement screenshot if csfloat does not offer one and if available
const detailButtons = container.querySelector('.detail-buttons');
if (detailButtons && container.querySelectorAll('.detail-buttons > button').length == 0 && cw_data.img) {
CSFloatHelpers.addReplacementScreenshotButton(detailButtons, item.item_name.includes('Crimson') ? 'rgb(69 10 10)' : 'rgb(101 163 13)', cw_data.img);
CSFloatHelpers.addReplacementScreenshotButton(container, item.item_name.includes('Crimson') ? 'rgb(69 10 10)' : 'rgb(101 163 13)', cw_data.img);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/eventhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
cacheSkinbidUserCurrency,
cacheSpItems,
cacheSpPopupItem,
cacheSpMinOrderPrice,
cacheCSFLocation,
cacheCSFExchangeRates,
} from './mappinghandler';
Expand Down Expand Up @@ -131,6 +132,7 @@ function processSkinportEvent(eventData: EventData<unknown>) {
// Data from first page load
const data = eventData.data as Skinport.UserData;
cacheSkinportCurrencyRates(data.rates, data.currency);
cacheSpMinOrderPrice(data.limits.minOrderValue);
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/mappinghandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ let skinportItems: Skinport.Item[] = [];
let skinportPopupItem: Skinport.ItemData | null = null;
// skinport: cached currency rates by Skinport: USD -> X
let skinportRatesFromUSD: { [currency: string]: number } = {};
// skinport: csrf token
let skinportCSRF = '';
// skinport: minimum order price
let skinportMinOrderPrice = 0;
// skinbid: cached currency rates by Skinbid: EUR -> X
let skinbidRates: Skinbid.ExchangeRates = [];
// skinport: cached currency rates by exchangerate.host: USD -> X
Expand Down Expand Up @@ -89,6 +93,10 @@ export function cacheCSFLocation(data: CSFloat.Location) {
csfloatLocation = data;
}

export function cacheSpMinOrderPrice(price: number) {
skinportMinOrderPrice = price;
}

export function cacheCSFPopupItem(data: CSFloat.ListingData) {
csfloatPopupItem = data;
}
Expand All @@ -106,13 +114,18 @@ export function cacheSpItems(data: Skinport.Item[]) {
}

export function cacheSkinportCurrencyRates(data: { [currency: string]: number }, user: string) {
// maybe cache csrf token here as well
if (Object.keys(skinportRatesFromUSD).length > 0) {
console.debug('[BetterFloat] Currency rates already cached, overwriting old ones: ', skinportRatesFromUSD);
}
skinportRatesFromUSD = data;
skinportUserCurrency = user;
}

export function cacheSkinportCSRF(token: string) {
skinportCSRF = token;
}

export function cacheSkinbidCurrencyRates(rates: Skinbid.ExchangeRates) {
skinbidRates = rates;
}
Expand All @@ -128,6 +141,11 @@ export function cacheRealCurrencyRates(data: { [currency: string]: number }) {
realRatesFromUSD = data;
}


export function getSpMinOrderPrice() {
return skinportMinOrderPrice;
}

// USD / rate = target currency
export async function getCSFCurrencyRate(currency: string) {
if (Object.keys(csfloatRates).length == 0) {
Expand All @@ -138,6 +156,7 @@ export async function getCSFCurrencyRate(currency: string) {

export function getCSFUserCurrency() {
return csfloatLocation?.inferred_location.currency ?? 'USD';

}

export function getWholeHistory() {
Expand Down Expand Up @@ -240,6 +259,13 @@ export async function getSpUserCurrencyRate(rates: 'skinport' | 'real' = 'real')
return rates == 'real' ? realRatesFromUSD[skinportUserCurrency] : skinportRatesFromUSD[skinportUserCurrency];
}

export async function getSpCSRF() {
if (skinportCSRF == '') {
await fetchUserData();
}
return skinportCSRF;
}

export async function getSkbUserCurrencyRate() {
if (skinbidUserCurrency == '') {
skinbidUserCurrency = document.querySelector('.currency-selector .hide-mobile')?.textContent?.trim() ?? 'USD';
Expand Down Expand Up @@ -273,6 +299,7 @@ async function fetchUserData() {
.then((data: Skinport.UserData) => {
console.debug('[BetterFloat] Received user data from Skinport manually: ', data);
cacheSkinportCurrencyRates(data.rates, data.currency);
cacheSkinportCSRF(data.csrf);
});
}

Expand Down
17 changes: 17 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ function addListeners() {
$('.MainContent').css('height', '528px');
$('.Warning').show(100);
});
$('input[type=text]').on('change', function () {
const attrName = $(this).attr('name');
if (attrName) {
chrome.storage.local.set({
[attrName]: $(this).val(),
});
}
$('.SideBar').css('height', '528px');
$('.MainContent').css('height', '528px');
$('.Warning').show(100);
});

// add listeners to all dropdowns
$('select').on('change', function () {
const attrName = $(this).attr('name');
Expand Down Expand Up @@ -241,6 +253,7 @@ function loadForSkinport() {
const checkBoxesElement = <HTMLInputElement>document.getElementById('SkinportCheckboxes');
const stickerPriceElement = <HTMLInputElement>document.getElementById('SkinportStickerPrices');
const skinportBlueGem = <HTMLInputElement>document.getElementById('InputCSBlueGem');
const skinportOneClickBuy = <HTMLInputElement>document.getElementById('InputOneClickBuy');
const skinportSteamPrice = <HTMLInputElement>document.getElementById('SkinportSteamPrice');
const skinportInputBuffDifference = <HTMLInputElement>document.getElementById('SkinportInputBuffDifference');
const skinportAutoClosePopup = <HTMLInputElement>document.getElementById('SkinportInputClosePopup');
Expand Down Expand Up @@ -270,6 +283,10 @@ function loadForSkinport() {
} else {
skinportBlueGem.checked = false;
}
if (data.ocoAPIKey) {
skinportOneClickBuy.value = data.ocoAPIKey;
}

if (data.skinportRates) {
(<HTMLSelectElement>document.getElementById('SkinportCurrencyConversion')).value = data.skinportRates;
}
Expand Down
Loading

0 comments on commit 9438ae9

Please sign in to comment.