Skip to content

Commit

Permalink
🔧 Refactor code to improve readability and performance
Browse files Browse the repository at this point in the history
- Updated index.ts: Changed the query selector to select the second element instead of the first one.
- Updated playerMatchDataLarger.ts: Removed unnecessary code related to styling and adjusted query selectors.
- Updated setPlayerInfo.ts: Removed console.log statement.

These changes refactor the code by making it more concise, removing unnecessary styling, and improving performance.
  • Loading branch information
creazy231 committed Sep 4, 2024
1 parent 2a507da commit 1cd4938
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = BXYGXAJ99T;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "iOS (App)/Info.plist";
Expand All @@ -708,7 +708,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand All @@ -731,7 +731,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = BXYGXAJ99T;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "iOS (App)/Info.plist";
Expand All @@ -747,7 +747,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand Down Expand Up @@ -836,7 +836,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Tools for Autodarts.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = BXYGXAJ99T;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -850,7 +850,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand All @@ -873,7 +873,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "macOS (App)/Tools for Autodarts.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = BXYGXAJ99T;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -887,7 +887,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion entrypoints/lobby.content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default defineContentScript({
const userEl = userElements?.filter(el => el.textContent?.trim() === username);

if (userEl.length) {
const removeBtn = userEl[0].closest("tr")?.querySelector("button:last-of-type") as HTMLButtonElement;
const removeBtn = userEl[1].closest("tr")?.querySelector("button:last-of-type") as HTMLButtonElement;
removeBtn?.click();
startPlayerToBoardObserver();
} else {
Expand Down
6 changes: 2 additions & 4 deletions entrypoints/match.content/playerMatchDataLarger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ export async function playerMatchDataLarger() {
const legsSetsLargerSize = config.legsSetsLarger.value || 3;
const playerMatchDataSize = config.playerMatchData.value || 1.5;
document.querySelectorAll(".ad-ext-player").forEach((playerCardEl) => {
playerCardEl?.nextElementSibling?.querySelectorAll(":scope > div > div > div").forEach((playerMatchDataEl) => {
playerCardEl?.querySelectorAll("div > div > div > span").forEach((playerMatchDataEl) => {
if (config.legsSetsLarger.enabled && playerMatchDataEl) {
(playerMatchDataEl as HTMLElement).style.height = `${legsSetsLargerSize}rem`;
(playerMatchDataEl as HTMLElement).style.width = `${legsSetsLargerSize}rem`;
playerMatchDataEl.querySelector("p")!.style.fontSize = `${legsSetsLargerSize}rem`;
}
});
if (config.playerMatchData.enabled) {
(playerCardEl?.nextElementSibling?.querySelector(":scope > div > p") as HTMLElement | null)!.style.fontSize = `${playerMatchDataSize}rem`;
(playerCardEl?.querySelector("div:last-of-type > p") as HTMLElement | null)!.style.fontSize = `${playerMatchDataSize}rem`;
}
});
} catch (e) {
Expand Down
2 changes: 0 additions & 2 deletions entrypoints/match.content/setPlayerInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export async function setPlayerInfo() {
};
});

console.log(playerInfo);

await AutodartsToolsMatchStatus.setValue({
...matchStatus,
playerCount,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "autodarts-tools",
"description": "Autodarts Tools enhances the gaming experience on autodarts.io",
"version": "1.5.0",
"version": "1.5.1",
"type": "module",
"author": {
"name": "Tobias Thiele",
Expand Down
2 changes: 1 addition & 1 deletion utils/getElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getWinnerPlayerCard = () => document.querySelector(".ad-ext-player-

export const getDartsThrown = (playerCard: HTMLElement) => playerCard?.nextElementSibling?.querySelector(":scope > div > p")?.textContent?.split("|")?.[0]?.trim().split("#")?.[1] || "";
export function getStats(playerCard: HTMLElement) {
return playerCard?.querySelector("div > p:last-of-type")?.textContent?.split("|")?.[1]?.trim() || playerCard?.querySelector("div > p:last-of-type")?.textContent?.split(":")?.[1]?.trim() || playerCard?.querySelector("div > p:last-of-type")?.textContent || "";
return playerCard?.querySelector("div > div:last-of-type > p")?.textContent?.split("|")?.[1]?.trim() || playerCard?.querySelector("div > p:last-of-type")?.textContent?.split(":")?.[1]?.trim() || playerCard?.querySelector("div > p:last-of-type")?.textContent || "";
}

export const getUndoBtn = () => [ ...document.getElementById("ad-ext-turn")?.nextElementSibling?.querySelectorAll("button") as NodeListOf<HTMLButtonElement> ].find(el => el.textContent === "Undo");
Expand Down
Loading

0 comments on commit 1cd4938

Please sign in to comment.