Skip to content

Commit

Permalink
ref: implement reloadTab()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sv443 committed Nov 23, 2024
1 parent 0e35c6a commit 1e34145
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataStore, compress, type DataMigrationsDict, decompress, type LooseUnion, clamp } from "@sv443-network/userutils";
import { disableBeforeUnload, featInfo } from "./features/index.js";
import { compressionSupported, error, getVideoTime, info, log, t, type TrLocale } from "./utils/index.js";
import { compressionSupported, error, getVideoTime, info, log, reloadTab, t, type TrLocale } from "./utils/index.js";
import { emitSiteEvent } from "./siteEvents.js";
import { compressionFormat } from "./constants.js";
import { emitInterface } from "./interface.js";
Expand Down Expand Up @@ -264,7 +264,7 @@ export async function promptResetConfig() {
location.replace(url.href);
}
else
location.reload();
await reloadTab();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/importCfg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { error, tryToDecompressAndParse, t, warn, log } from "../utils/index.js";
import { error, tryToDecompressAndParse, t, warn, log, reloadTab } from "../utils/index.js";
import { BytmDialog } from "../components/index.js";
import { scriptInfo } from "../constants.js";
import { emitSiteEvent } from "../siteEvents.js";
Expand Down Expand Up @@ -109,7 +109,7 @@ async function renderFooter() {

if(await showPrompt({ type: "confirm", message: t("import_success_confirm_reload") })) {
disableBeforeUnload();
return location.reload();
return reloadTab();
}

emitSiteEvent("rebuildCfgMenu", parsed.data);
Expand Down
4 changes: 2 additions & 2 deletions src/features/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatNumber, getLocale, getPreferredLocale, getResourceUrl, resourceAsString, t, tp } from "../utils/index.js";
import { formatNumber, getLocale, getPreferredLocale, getResourceUrl, reloadTab, resourceAsString, t, tp } from "../utils/index.js";
import { clearLyricsCache, getLyricsCache } from "./lyricsCache.js";
import { doVersionCheck } from "./versionCheck.js";
import { getFeature, promptResetConfig } from "../config.js";
Expand Down Expand Up @@ -785,7 +785,7 @@ export const featInfo = {
message: t("reset_everything_confirm"),
})) {
await getStoreSerializer().resetStoresData();
location.reload();
await reloadTab();
}
},
advanced: true,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { compress, decompress, pauseFor, type Stringifiable } from "@sv443-network/userutils";
import { addStyle, addStyleFromResource, domLoaded, getResourceUrl, setGlobalCssVars, warn } from "./utils/index.js";
import { addStyle, addStyleFromResource, domLoaded, getResourceUrl, reloadTab, setGlobalCssVars, warn } from "./utils/index.js";
import { clearConfig, fixCfgKeys, getFeatures, initConfig, setFeatures } from "./config.js";
import { buildNumber, compressionFormat, defaultLogLevel, mode, scriptInfo } from "./constants.js";
import { dbg, error, getDomain, info, getSessionId, log, setLogLevel, initTranslations, setLocale } from "./utils/index.js";
Expand Down Expand Up @@ -382,7 +382,7 @@ function registerDevCommands() {
if(confirm("Reset the configuration to its default values?\nThis will automatically reload the page.")) {
await clearConfig();
disableBeforeUnload();
location.reload();
await reloadTab();
}
}, "r");

Expand All @@ -391,7 +391,7 @@ function registerDevCommands() {
await setFeatures(fixCfgKeys(oldFeats));
dbg("Fixed missing or extraneous config values.\nFrom:", oldFeats, "\n\nTo:", getFeatures());
if(confirm("All missing or config values were set to their default values and extraneous ones were removed.\nDo you want to reload the page now?"))
location.reload();
await reloadTab();
});

GM.registerMenuCommand("List GM values in console with decompression", async () => {
Expand Down
8 changes: 4 additions & 4 deletions src/menu/menu_old.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { compress, debounce, isScrollable, type Stringifiable } from "@sv443-net
import { type defaultData, formatVersion, getFeature, getFeatures, migrations, setFeatures } from "../config.js";
import { buildNumber, compressionFormat, host, mode, scriptInfo } from "../constants.js";
import { featInfo, disableBeforeUnload } from "../features/index.js";
import { error, getResourceUrl, info, log, resourceAsString, getLocale, hasKey, initTranslations, setLocale, t, arrayWithSeparators, tp, type TrKey, onInteraction, getDomain, copyToClipboard, warn, compressionSupported, tryToDecompressAndParse, setInnerHtml, type TrLocale, tl } from "../utils/index.js";
import { error, getResourceUrl, info, log, resourceAsString, getLocale, hasKey, initTranslations, setLocale, t, arrayWithSeparators, tp, type TrKey, onInteraction, getDomain, copyToClipboard, warn, compressionSupported, tryToDecompressAndParse, setInnerHtml, type TrLocale, tl, reloadTab } from "../utils/index.js";
import { emitSiteEvent, siteEvents } from "../siteEvents.js";
import { getChangelogDialog, getFeatHelpDialog, showPrompt } from "../dialogs/index.js";
import type { FeatureCategory, FeatureKey, FeatureConfig, HotkeyObj, FeatureInfo } from "../types.js";
Expand Down Expand Up @@ -185,7 +185,7 @@ async function mountCfgMenu() {
reloadTxtEl.addEventListener("click", () => {
closeCfgMenu();
disableBeforeUnload();
location.reload();
reloadTab();
});

reloadFooterEl.appendChild(reloadTxtEl);
Expand Down Expand Up @@ -244,7 +244,7 @@ async function mountCfgMenu() {

if(await showPrompt({ type: "confirm", message: t("import_success_confirm_reload") })) {
disableBeforeUnload();
return location.reload();
return reloadTab();
}

exImDlg.unmount();
Expand Down Expand Up @@ -333,7 +333,7 @@ async function mountCfgMenu() {
})) {
closeCfgMenu();
disableBeforeUnload();
location.reload();
reloadTab();
}
}
else if(getLocale() !== featConf.locale)
Expand Down
3 changes: 2 additions & 1 deletion src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { showPrompt } from "./dialogs/prompt.js";
import { t } from "./utils/translations.js";
import { error } from "./utils/logging.js";
import { downloadFile } from "./utils/dom.js";
import { reloadTab } from "./utils/misc.js";
import packageJson from "../package.json" with { type: "json" };

/** Central serializer for all data stores */
Expand Down Expand Up @@ -38,7 +39,7 @@ export async function importData(blob: File | Blob) {
message: t("import_success_confirm_reload"),
});

reload && location.reload();
reload && await reloadTab();
}
catch(err) {
error(err);
Expand Down

0 comments on commit 1e34145

Please sign in to comment.