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
1import { getUserDetails } from "@/utils/utilities";
2import { preferences } from "@/utils/storage";
3import config from "@/utils/config.json";
4
5import * as discovery from "./discovery";
6import * as view from "./view";
7import * as apiTypes from "@/utils/types";
8
9export default defineContentScript({
10 matches: ["*://polytoria.com/store/*"],
11 main() {
12 preferences.getPreferences()
13 .then((values) => {
14 getUserDetails()
15 .then((user) => {
16 if (!user) {
17 // Error page or event page most likely, where users are not authenticated
18 console.warn("[Poly+] Failure to get logged in user details.");
19 return;
20 }
21
22 if (!window.location.pathname.split("/")[2]) {
23 // Discovery
24 if (config.devBuild) {
25 console.log(
26 "[Poly+] Running discovery page functions: ",
27 discovery,
28 );
29 }
30
31 if (values.enabled.includes("irlBrickPrice")) {
32 discovery.irlBrickPrice();
33 }
34 if (values.enabled.includes("storeOwnedTags")) {
35 discovery.ownedTags(user.userId);
36 }
37 } else {
38 // View
39 if (config.devBuild) {
40 console.log("[Poly+] Running view page functions: ", view);
41 }
42
43 if (values.enabled.includes("irlBrickPrice")) {
44 view.irlBrickPrice();
45 }
46 if (values.enabled.includes("tryItems")) {
47 view.tryOn(user as apiTypes.userDetails);
48 }
49 if (values.enabled.includes("accurateOwners")) {
50 view.accurateOwnerCount();
51 }
52 }
53 });
54 });
55 },
56});