A rewrite of Poly+, my quality-of-life browser extension for Polytoria. Built entirely fresh using the WXT extension framework, Typescript, and with added better overall code quality.
extension

feat: Place Approx. Revenue

Index aa55f973 cea81887

Changed files
+92 -7
entrypoints
places.content
store.content
utils
+1
entrypoints/places.content/index.ts
···
if (window.location.pathname.split('/')[2]) {
// View
if (values.favoritedPlaces.enabled) view.favoritedPlaces();
+
view.approxPlaceRevenue();
}
});
}
+50 -1
entrypoints/places.content/view.ts
···
import config from "@/utils/config.json";
import { _favoritedPlaces } from "@/utils/storage";
import { expireCache } from "@/utils/utilities";
+
import * as apiTypes from "@/utils/api/types";
const placeID = window.location.pathname.split('/')[2];
/**
···
storage.watch<Array<string>>('sync:favoritedPlaces', (value, previous) => {
placeIDs = value!;
});
-
}
+
};
+
+
/**
+
* Displays the approximated amount of revenue generated from a certain place, based off the unique visits & any gamepass sales (taking into account the creator's current membership tax)
+
*/
+
export async function approxPlaceRevenue() {
+
const round = (number: number) => Math.round(number / config.economy.visitorPayouts.visitors) * config.economy.visitorPayouts.visitors;
+
const infoCard = document.querySelector('.card-body .row:has(.fa-calendar)')!;
+
+
const key = document.createElement('li');
+
const value = document.createElement('li');
+
+
key.innerHTML = 'Revenue:';
+
value.innerHTML = '...';
+
value.classList.add(config.api.enabled ? 'text-success' : 'text-muted');
+
+
infoCard.children[0].appendChild(key);
+
infoCard.children[1].appendChild(value);
+
+
const revenue = await pullCache(
+
"placeRevenue",
+
async () => {
+
if (!config.api.enabled) return "disabled";
+
+
const place: apiTypes.placeApiSchema = (await (await fetch(config.api.urls.public + 'places/' + placeID)).json());
+
const store: apiTypes.gamepassesApiSchema = (await (await fetch(config.api.urls.public + 'places/' + placeID + '/gamepasses')).json());
+
const creator: apiTypes.userApiSchema = (await (await fetch(config.api.urls.public + 'users/' + place.creator.id)).json());
+
+
const visitorPayout = round(place.uniqueVisits) / config.economy.visitorPayouts.visitors;
+
let gamepassRevenue = 0;
+
+
for (const gamepass of store.gamepasses) {
+
const price = Math.floor(gamepass.asset.price - (gamepass.asset.price * config.economy.membershipTax[creator.membershipType]))
+
gamepassRevenue += price * gamepass.asset.sales;
+
};
+
+
return visitorPayout + gamepassRevenue;
+
},
+
300000,
+
false
+
);
+
+
if (revenue == "disabled") {
+
value.innerText = 'Sorry, this feature is currently unavailable! Check back later!';
+
throw new Error("[Poly+] API is disabled, cancelling approx. place revenue loading..");
+
};
+
+
value.innerHTML = '<i class="pi pi-brick me-2"></i> ~' + revenue.toLocaleString();
+
};
+1 -1
entrypoints/store.content/index.ts
···
if (values.storeOwnedTags.enabled) discovery.ownedTags(user.userId);
} else {
// View
-
if (config.devBuild) console.log('[Poly+] Running view page functions: ', discovery);
+
if (config.devBuild) console.log('[Poly+] Running view page functions: ', view);
if (values.irlBrickPrice.enabled) view.irlBrickPrice();
if (values.tryItems.enabled) view.tryOn(user as apiTypes.userDetails);
+24 -3
utils/api/types.ts
···
profileViews: number,
forumPosts: number,
assetSales: number,
-
membershipType: string,
+
membershipType: "free" | "plus" | "plusDeluxe",
isStaff: boolean,
registeredAt: string,
lastSeenAt: string
···
id: number,
name: string,
description: string,
-
creator: object,
+
creator: {
+
type: "user" | "guild",
+
id: number,
+
name: string,
+
thumbnail: string
+
},
thumbnail: string,
genre: string,
maxPlayers: number,
···
playing: number,
rating: object,
accessType: string,
-
accessPrice: number|null,
+
accessPrice: number | null,
createdAt: string,
updatedAt: string
};
···
code: string,
message: string
}>
+
};
+
+
export type gamepassesApiSchema = {
+
gamepasses: Array<{
+
id: number,
+
asset: {
+
id: number,
+
name: string,
+
description: string,
+
thumbnail: string,
+
price: number,
+
sales: number
+
}
+
}>,
+
pages: number,
+
total: number
};
+11
utils/config.json
···
},
"limits": {
"favoritedPlaces": 15
+
},
+
"economy": {
+
"membershipTax": {
+
"free": 0.35,
+
"plus": 0.25,
+
"plusDeluxe": 0.15
+
},
+
"visitorPayouts": {
+
"visitors": 5,
+
"payout": 1
+
}
}
}
+4 -2
utils/storage.ts
···
storeOwnedTags: { enabled: true },
membershipThemes: { enabled: false, themeId: "plus" },
tryItems: { enabled: true },
-
outfitCost: { enabled: true }
+
outfitCost: { enabled: true },
+
placeRevenue: { enabled: true }
}
export type preferencesSchema = typeof defaultPreferences & {
···
inventory: [],
userIDs: {},
avatars: {},
-
items: {}
+
items: {},
+
placeRevenue: {}
},
version: 1
});
+1
utils/types.ts
···
userIDs: Record<string, number>,
avatars: Record<string, apiTypes.avatarApiSchema>,
items: Record<string, apiTypes.itemApiSchema>,
+
placeRevenue: Record<string, number>,
[key: string]: any;
};