diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-03-22 11:37:34 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-03-22 11:37:34 +0300 |
| commit | 254bc97e737a568cb23fbbcb773f0dfb8894b9ff (patch) | |
| tree | 850c6dceda07214248c3bfa2bf3bf0e15fa3e329 /src/appcommon.ts | |
| parent | 6c991424547b149b3cac70a94a4e14f3661908a6 (diff) | |
| download | the-epube-typescript-native.tar.gz the-epube-typescript-native.tar.xz | |
wip typescript stuff typescript-native
Diffstat (limited to 'src/appcommon.ts')
| -rw-r--r-- | src/appcommon.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/appcommon.ts b/src/appcommon.ts new file mode 100644 index 0000000..393b781 --- /dev/null +++ b/src/appcommon.ts @@ -0,0 +1,43 @@ +declare var EpubeApp: any; + +export class AppCommon { + urlParam(name){ + try { + const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0; + } catch (e) { + return 0; + } + } + + isOnline() { + if (typeof EpubeApp != "undefined" && typeof EpubeApp.isOnline != "undefined") + return EpubeApp.isOnline(); + else + return navigator.onLine; + } + + initNightMode() { + if (typeof EpubeApp != "undefined") { + this.applyNightMode(EpubeApp.isNightMode()); + return; + } + + if (window.matchMedia) { + const mql = window.matchMedia('(prefers-color-scheme: dark)'); + + mql.addEventListener("change", () => { + this.applyNightMode(mql.matches); + }); + + this.applyNightMode(mql.matches); + } + } + + applyNightMode(is_night) { + console.log("night mode changed to", is_night); + + $("#theme_css").attr("href", + "lib/bootstrap/v3/css/" + (is_night ? "theme-dark.min.css" : "bootstrap-theme.min.css")); + } +} |
