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: Show "Owners" instead of "Sales" feature

Index 6ffd0217 352cbd1a

Changed files
+48 -4
entrypoints
forum.content
store.content
utils
-2
entrypoints/forum.content/view.ts
···
-
import { preferences } from "@/utils/storage";
-
/**
* Detects any username mentions in a forum post and turns them into clickable links.
*/
+1
entrypoints/store.content/index.ts
···
if (values.irlBrickPrice.enabled) view.irlBrickPrice();
if (values.tryItems.enabled) view.tryOn(user as apiTypes.userDetails);
+
if (values.accurateOwners.enabled) view.accurateOwnerCount();
};
})
});
+29
entrypoints/store.content/view.ts
···
import { userDetails } from "@/utils/types";
import * as apiTypes from "@/utils/api/types";
+
const itemID = window.location.pathname.split('/')[2];
+
/**
* Adds the locale real-life dollar value next to the amount of bricks an item costs in the text of the purchase button.
*/
···
modal.showModal();
});
+
};
+
+
/**
+
* Replaces the item sales counter with the number of owners the item has, useful for items that were granted by staff or earned via an event.
+
*/
+
export async function accurateOwnerCount() {
+
const counter = document.querySelectorAll('.col.text-center')[2]!;
+
if (!counter || counter.children[1].textContent!.trim() != '0') return;
+
+
const owners: "disabled" | number = await pullKVCache(
+
"ownerCount",
+
itemID,
+
async () => {
+
if (!config.api.enabled) return "disabled";
+
const res: apiTypes.ownersApiSchema = (await (await fetch(config.api.urls.public + 'store/' + itemID + '/owners')).json());
+
return res.total;
+
},
+
60000, // 1 minute
+
false
+
);
+
+
if (owners == "disabled") {
+
throw new Error("[Poly+] API disabled, cancelling accurate item owner count loading..");
+
};
+
+
(counter.children[0] as HTMLHeadingElement).innerText = 'Owners';
+
(counter.children[1] as HTMLHeadingElement).innerText = owners.toLocaleString();
};
+13
utils/api/types.ts
···
}>,
pages: number,
total: number
+
};
+
+
export type ownersApiSchema = {
+
inventories: Array<{
+
serial: number,
+
purchasedAt: string,
+
user: {
+
id: number,
+
username: string
+
}
+
}>,
+
pages: number,
+
total: number
};
+4 -2
utils/storage.ts
···
membershipThemes: { enabled: false, themeId: "plus" },
tryItems: { enabled: true },
outfitCost: { enabled: true },
-
placeRevenue: { enabled: true }
+
placeRevenue: { enabled: true },
+
accurateOwners: { enabled: true }
}
export type preferencesSchema = typeof defaultPreferences & {
···
userIDs: {},
avatars: {},
items: {},
-
placeRevenue: {}
+
placeRevenue: {},
+
ownerCount: {}
},
version: 1
});
+1
utils/types.ts
···
avatars: Record<string, apiTypes.avatarApiSchema>,
items: Record<string, apiTypes.itemApiSchema>,
placeRevenue: Record<string, number>,
+
ownerCount: Record<string, number>,
[key: string]: any;
};