From 3b2b8bf30027e41e74f90f3adbc1474400599aca Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 26 Jun 2023 20:24:48 +0800 Subject: [PATCH] Hide scrollbar on Windows Chrome --- import_map.json | 3 ++- islands/TaskManager.tsx | 8 ++++++++ routes/index.tsx | 27 +++++++++++++++++++++++---- static/common.css | 6 ++++++ static/hide-scrollbar.css | 3 +++ static/sw.ts | 6 +++++- 6 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 static/hide-scrollbar.css diff --git a/import_map.json b/import_map.json index 6b15564..ab7dbee 100644 --- a/import_map.json +++ b/import_map.json @@ -20,6 +20,7 @@ "lifegpc-md5": "https://esm.sh/lifegpc-md5@1.0.3", "meilisearch": "https://esm.sh/meilisearch@0.33.0", "lodash/": "https://esm.sh/lodash@4.17.21/", - "mime": "https://esm.sh/mime@3.0.0" + "mime": "https://esm.sh/mime@3.0.0", + "ua-parser-js": "https://esm.sh/ua-parser-js@1.0.35" } } diff --git a/islands/TaskManager.tsx b/islands/TaskManager.tsx index 650db8f..4c6daed 100644 --- a/islands/TaskManager.tsx +++ b/islands/TaskManager.tsx @@ -167,6 +167,14 @@ export default class TaskManager extends Component { if (!this.props.show) return null; return (
+ { + set_state(`${this.props.base}/new`); + }} + > + add +

count

diff --git a/routes/index.tsx b/routes/index.tsx index e7acf47..ff3300d 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -3,19 +3,38 @@ import { Handlers, PageProps } from "$fresh/server.ts"; import GlobalContext from "../components/GlobalContext.tsx"; import Container from "../islands/Container.tsx"; import { get_i18nmap, i18n_handle_request } from "../server/i18ns.ts"; +import parse_ua from "ua-parser-js"; -export const handler: Handlers = { +type Props = { + lang: string; + userAgent: string | null; +}; + +export const handler: Handlers = { GET(req, ctx) { const re = i18n_handle_request(req); - if (typeof re === "string") return ctx.render(re); + if (typeof re === "string") { + return ctx.render({ + lang: re, + userAgent: req.headers.get("User-Agent"), + }); + } return re; }, }; -export default function Index({ data }: PageProps) { - const i18n = get_i18nmap(data); +export default function Index({ data }: PageProps) { + const i18n = get_i18nmap(data.lang); + const ua = parse_ua(data.userAgent || ""); + const is_windows_chrome = ua.browser.name === "Chrome" && + ua.os.name === "Windows"; return ( + + {is_windows_chrome + ? + : null} + diff --git a/static/common.css b/static/common.css index bb8b347..1c847ac 100644 --- a/static/common.css +++ b/static/common.css @@ -214,3 +214,9 @@ body { .mdc-top-app-bar__section--align-end>* { margin: 0 5px; } + +.task_manager .new_task { + position: fixed; + right: 50px; + bottom: 50px; +} diff --git a/static/hide-scrollbar.css b/static/hide-scrollbar.css new file mode 100644 index 0000000..3fdeac9 --- /dev/null +++ b/static/hide-scrollbar.css @@ -0,0 +1,3 @@ +html::-webkit-scrollbar { + display: none; +} diff --git a/static/sw.ts b/static/sw.ts index 7b1afb9..bdf558b 100644 --- a/static/sw.ts +++ b/static/sw.ts @@ -27,7 +27,11 @@ self.addEventListener("activate", (event: ActivateEvent) => { event.waitUntil(deleteOldCaches()); }); -const CACHES = ["/common.css", "/preact-material-components/style.css"]; +const CACHES = [ + "/common.css", + "/hide-scrollbar.css", + "/preact-material-components/style.css", +]; function match_url(u: URL) { const pn = u.pathname;