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 { preferences } from "@/utils/storage";
2import config from "@/utils/config.json";
3import * as view from "./view";
4import { pullKVCache } from "@/utils/utilities";
5import { getAPI } from "@/utils/api";
6
7export default defineContentScript({
8 matches: ["*://polytoria.com/u/*", "*://polytoria.com/users/*"],
9 main() {
10 const publicAPI = getAPI("public");
11
12 preferences.getPreferences()
13 .then(async (values) => {
14 let userID;
15 const username = window.location.pathname.split("/")[2];
16
17 if (isNaN(username as any)) {
18 userID = await pullKVCache(
19 "userIDs",
20 username,
21 async () => {
22 if (!publicAPI.enabled) return "disabled";
23
24 const data = await (await fetch(
25 publicAPI.url + "users/find?username=" + username,
26 )).json();
27 return data.id;
28 },
29 -1,
30 false,
31 );
32 } else {
33 userID = username; // * Fallback for legacy profile URLs
34 }
35
36 if (window.location.pathname.split("/")[1] == "u") {
37 // View
38 if (config.devBuild) {
39 console.log("[Poly+] Running view page functions: ", view);
40 }
41
42 view.displayId(userID);
43 if (values.enabled.includes("outfitCost")) view.outfitCost(userID);
44 }
45 });
46 },
47});