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: preferences structure rewrite

Index 767b4102 7c804366

Changed files
+83 -58
entrypoints
account.content
forum.content
places.content
profile.content
store.content
public
utils
+1 -1
entrypoints/account.content/index.ts
···
.then((values) => {
if (window.location.pathname.includes("friends")) {
// View
-
if (values.improvedFriendLists.enabled) friends.actions();
+
if (values.enabled.includes("improvedFriendLists")) friends.actions();
}
});
},
+1 -1
entrypoints/forum.content/index.ts
···
.then((values) => {
if (window.location.pathname.includes("post")) {
// View
-
if (values.forumMentions.enabled) view.forumMentions();
+
if (values.enabled.includes("forumMentions")) view.forumMentions();
}
});
},
+3 -3
entrypoints/home.content.ts
···
main() {
preferences.getPreferences()
.then((values) => {
-
if (values.favoritedPlaces.enabled) favoritedPlaces();
-
if (values.bestFriends.enabled) bestFriends();
-
if (values.irlBrickPrice.enabled) irlBrickPrice();
+
if (values.enabled.includes("favoritedPlaces")) favoritedPlaces();
+
if (values.enabled.includes("bestFriends")) bestFriends();
+
if (values.enabled.includes("irlBrickPrice")) irlBrickPrice();
});
},
});
+10 -4
entrypoints/places.content/index.ts
···
console.log("[Poly+] Running view page functions: ", view);
}
-
if (values.favoritedPlaces.enabled) view.favoritedPlaces();
-
if (values.placeRevenue.enabled) view.approxPlaceRevenue();
-
} else if (first === "create" && values.placeManagement.enabled) {
+
if (values.enabled.includes("favoritedPlaces")) {
+
view.favoritedPlaces();
+
}
+
if (values.enabled.includes("placeRevenue")) {
+
view.approxPlaceRevenue();
+
}
+
} else if (
+
first === "create" && values.enabled.includes("placeManagement")
+
) {
// Manage
if (config.devBuild) {
console.log("[Poly+] Running manage page functions: ", manage);
}
-
if (values.placeManagement.download) manage.placeFileExport();
+
if (values.config.placeManagement.download) manage.placeFileExport();
}
});
},
+23 -12
entrypoints/preferences-handler.ts
···
async () => {
saveBtn.removeAttribute("disabled");
-
const state = !values[_.setting].enabled;
-
values[_.setting].enabled = state;
-
updateState(container, state);
+
const state = getState(_.setting);
+
if (state) {
+
values.enabled = values.enabled.filter((item) =>
+
item !== _.setting
+
);
+
} else {
+
values.enabled.push(_.setting);
+
}
+
updateState(container, !state);
},
);
}
···
"-": "secondary",
};
-
const state = await getState(data.setting);
+
const state = getState(data.setting);
const container = document.createElement("div");
container.id = data.setting;
···
select.addEventListener("change", function () {
document.getElementById("save")!.removeAttribute("disabled");
-
values[data.setting][subsetting.subsetting] =
-
select.options[select.selectedIndex].value;
+
(values.config[data.setting as keyof typeof values.config] as Record<
+
string,
+
any
+
>)[subsetting.subsetting] = select.options[select.selectedIndex].value;
});
div.appendChild(select);
···
"change",
() => {
document.getElementById("save")!.removeAttribute("disabled");
-
values[data.setting][subsetting.subsetting] = checkbox.checked;
+
(values.config[data.setting as keyof typeof values.config] as Record<
+
string,
+
any
+
>)[subsetting.subsetting] = checkbox.checked;
},
);
···
toggleBtn.classList.toggle("btn-success", !state);
toggleBtn.classList.toggle("btn-danger", state);
}
-
-
async function getState(name: string): Promise<boolean | null> {
-
const state = values[name] ?? (defaultPreferences as preferencesSchema)[name];
-
if (!state) return null;
-
return state.enabled;
+
function getState(name: string) {
+
if (values.enabled.includes(name)) {
+
return true;
+
}
+
return (defaultPreferences as preferencesSchema).enabled.includes(name);
}
function createTag(name: Tags) {
+1 -1
entrypoints/profile.content/index.ts
···
}
view.displayId(userID);
-
if (values.outfitCost.enabled) view.outfitCost(userID);
+
if (values.enabled.includes("outfitCost")) view.outfitCost(userID);
}
});
},
+4 -4
entrypoints/sitewide.content.ts
···
preferences.getPreferences()
.then((values) => {
-
if (values.irlBrickPrice.enabled) {
+
if (values.enabled.includes("irlBrickPrice")) {
const currency = bricksToCurrency(user.bricks, "USD");
if (currency) {
document.getElementsByClassName("brickBalanceCount")[0]
···
}
}
-
if (values.hideNotificationBadges.enabled) {
+
if (values.enabled.includes("hideNotificationBadges")) {
const badges = document.getElementsByClassName(
"notif-nav notif-sidebar",
);
···
}
}
-
if (values.membershipThemes.enabled) {
+
if (values.enabled.includes("membershipThemes")) {
membershipThemes(
-
values.membershipThemes.themeId as "plus" | "plusdx",
+
values.config.membershipThemes.themeId as "plus" | "plusdx",
);
}
});
+11 -5
entrypoints/store.content/index.ts
···
);
}
-
if (values.irlBrickPrice.enabled) discovery.irlBrickPrice();
-
if (values.storeOwnedTags.enabled) {
+
if (values.enabled.includes("irlBrickPrice")) {
+
discovery.irlBrickPrice();
+
}
+
if (values.enabled.includes("storeOwnedTags")) {
discovery.ownedTags(user.userId);
}
} else {
···
console.log("[Poly+] Running view page functions: ", view);
}
-
if (values.irlBrickPrice.enabled) view.irlBrickPrice();
-
if (values.tryItems.enabled) {
+
if (values.enabled.includes("irlBrickPrice")) {
+
view.irlBrickPrice();
+
}
+
if (values.enabled.includes("tryItems")) {
view.tryOn(user as apiTypes.userDetails);
}
-
if (values.accurateOwners.enabled) view.accurateOwnerCount();
+
if (values.enabled.includes("accurateOwners")) {
+
view.accurateOwnerCount();
+
}
}
});
});
+3 -7
public/preferences.json
···
"name": "Hide User Ads",
"desc": "Hide those annoying user ads!",
"setting": "hideUserAds",
-
"notes": [
-
"!Ads that are shown to help support Polytoria are not hidden."
-
],
+
"notes": ["!Ads that are shown to help support Polytoria are not hidden."],
"config": [
{
"type": "check",
···
{
"name": "Game Profiles",
"desc": "Traverse a place view page that matches a place's color palette!",
-
"setting": "inlineEditing",
+
"setting": "gameProfiles",
"notes": [
"!Place creates must request a game profile for one to be made. Since this is experimental, no game profiles have or will be made.",
"!This feature will be expanded upon in the future."
···
"name": "Forum Unix Timestamps",
"desc": "See a date and time that is adjusted to everyone (who is using Poly+)'s local time.",
"setting": "forumTimestamps",
-
"notes": [
-
"!The styling for this feature is not yet done."
-
],
+
"notes": ["!The styling for this feature is not yet done."],
"tags": ["utility"]
}
]
+26 -20
utils/storage.ts
···
import { WxtStorageItem } from "wxt/storage";
export const defaultPreferences = {
-
favoritedPlaces: { enabled: true },
-
bestFriends: { enabled: true },
-
forumMentions: { enabled: true },
-
improvedFriendLists: { enabled: true },
-
irlBrickPrice: { enabled: true },
-
hideNotificationBadges: { enabled: false },
-
storeOwnedTags: { enabled: true },
-
membershipThemes: { enabled: false, themeId: "plus" },
-
tryItems: { enabled: true },
-
outfitCost: { enabled: true },
-
placeRevenue: { enabled: true },
-
accurateOwners: { enabled: true },
-
placeManagement: {
-
enabled: true,
-
activityToggle: true,
-
download: true,
-
multipleWhitelist: true,
-
clearWhitelist: true,
+
enabled: [
+
"favoritedPlaces",
+
"bestFriends",
+
"forumMentions",
+
"improvedFriendLists",
+
"irlBrickPrice",
+
"storeOwnedTags",
+
"tryItems",
+
"outfitCost",
+
"placeRevenue",
+
"accurateOwners",
+
],
+
config: {
+
membershipThemes: {
+
themeId: "plus",
+
},
+
placeManagement: {
+
activityToggle: true,
+
download: true,
+
multipleWhitelist: true,
+
clearWhitelist: true,
+
},
},
};
···
"sync:preferences",
{ fallback: defaultPreferences, version: 1 },
) as PreferencesStorageItem;
+
export const _favoritedPlaces = storage.defineItem("sync:favoritedPlaces", {
-
fallback: ["9656"],
+
fallback: [],
version: 1,
});
+
export const _bestFriends = storage.defineItem("sync:bestFriends", {
-
fallback: ["2782"],
+
fallback: [],
version: 1,
});