index.tsx
| 1 | /* @refresh reload */ |
| 2 | import { render } from "solid-js/web"; |
| 3 | import "./style.css"; |
| 4 | |
| 5 | import App from "./App"; |
| 6 | import { loadDataFromDB } from "./offline"; |
| 7 | |
| 8 | const root = document.getElementById("root"); |
| 9 | if (!(root instanceof HTMLElement)) { |
| 10 | throw new Error( |
| 11 | "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?", |
| 12 | ); |
| 13 | } |
| 14 | |
| 15 | function hasTouch() { |
| 16 | return ( |
| 17 | "ontouchstart" in document.documentElement || |
| 18 | navigator.maxTouchPoints > 0 || |
| 19 | ("msMaxTouchPoints" in navigator && |
| 20 | typeof navigator.msMaxTouchPoints === "number" && |
| 21 | navigator.msMaxTouchPoints > 0) |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | if (hasTouch()) { |
| 26 | // remove all the :hover stylesheets |
| 27 | try { |
| 28 | // prevent exception on browsers not supporting DOM styleSheets properly |
| 29 | for (const si in document.styleSheets) { |
| 30 | const styleSheet = document.styleSheets[si]; |
| 31 | if (!styleSheet.cssRules) continue; |
| 32 | |
| 33 | for (let ri = styleSheet.cssRules.length - 1; ri >= 0; ri--) { |
| 34 | const rule = styleSheet.cssRules[ri]; |
| 35 | if (!("selectorText" in rule) || typeof rule.selectorText !== "string" || !rule.selectorText) continue; |
| 36 | |
| 37 | if (rule.selectorText.match(":hover")) { |
| 38 | styleSheet.deleteRule(ri); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } catch {} |
| 43 | } |
| 44 | |
| 45 | loadDataFromDB() |
| 46 | .then(() => { |
| 47 | root.innerHTML = ""; |
| 48 | render(() => <App />, root); |
| 49 | }) |
| 50 | .catch((e) => { |
| 51 | root.innerHTML = e.toString(); |
| 52 | }); |
| 53 |