Skip to content

Commit

Permalink
Fix wishlist export dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tfedor committed May 28, 2024
1 parent 804ebc4 commit 5396802
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 22 additions & 13 deletions src/js/Content/Features/Store/Wishlist/FExportWishlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import HTML from "@Core/Html/Html";
import SteamFacade from "@Content/Modules/Facades/SteamFacade";
import UserNotes from "@Content/Features/Store/Common/UserNotes";
import Clipboard from "@Content/Modules/Clipboard";
import {ResettableTimer, Timer} from "@Core/Utils/TimeUtils";

type Wishlist = Array<[string, {
name: string,
Expand Down Expand Up @@ -138,7 +139,7 @@ export default class FExportWishlist extends Feature<CWishlist> {
*
* Final solution is to query the action buttons of the dialog and adding some extra click handlers on the content script side.
*/
_showDialog(wl: Array<[string, any]>): void {
async _showDialog(wl: Array<[string, any]>): Promise<void> {

async function exportWishlist(method: ExportMethod): Promise<void> {
const type = document.querySelector<HTMLInputElement>("input[name='es_wexport_type']:checked")!.value;
Expand Down Expand Up @@ -189,21 +190,29 @@ export default class FExportWishlist extends Feature<CWishlist> {
L(__export_copyClipboard)
);

const [dlBtn, copyBtn] = document.querySelectorAll(".newmodal_buttons > .btn_medium");
for (let i=0; i<10; i++) {
const [dlBtn, copyBtn] = document.querySelectorAll(".newmodal_buttons > .btn_medium");

// Update button to new style, remove when not needed
copyBtn!.classList.replace("btn_darkblue_white_innerfade", "btn_blue_steamui");
if (!dlBtn || !copyBtn) {
// wait for popup to show up to apply events
await new Timer(10);
continue;
}

// Capture this s.t. the CModal doesn't get destroyed before we can grab this information
dlBtn!.addEventListener("click", () => exportWishlist(ExportMethod.download), true);
copyBtn!.addEventListener("click", () => exportWishlist(ExportMethod.copyToClipboard), true);
// Update button to new style, remove when not needed
copyBtn!.classList.replace("btn_darkblue_white_innerfade", "btn_blue_steamui");

const format = document.querySelector<HTMLElement>(".es-wexport__format");
for (const el of document.getElementsByName("es_wexport_type")) {
el.addEventListener("click", e => {
const target = e.target as HTMLInputElement;
format!.classList.toggle("es-grayout", target.value === "json");
});
// Capture this s.t. the CModal doesn't get destroyed before we can grab this information
dlBtn!.addEventListener("click", () => exportWishlist(ExportMethod.download), true);
copyBtn!.addEventListener("click", () => exportWishlist(ExportMethod.copyToClipboard), true);

const format = document.querySelector<HTMLElement>(".es-wexport__format");
for (const el of document.getElementsByName("es_wexport_type")) {
el.addEventListener("click", e => {
const target = e.target as HTMLInputElement;
format!.classList.toggle("es-grayout", target.value === "json");
});
}
}
}
}
2 changes: 1 addition & 1 deletion src/js/Core/Utils/TimeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Timer {
export class Timer {

private _id: number|undefined;
private _promise: Promise<void>|null = null;
Expand Down

0 comments on commit 5396802

Please sign in to comment.