remove hover effect on touch screens

AuthorKonata <konata@posteo.jp>
Date
Commit818dbb5f3c5afefe24059b6e8577673c6ec2a00d
Parent9077cea
2 files changed, 32 insertions(+), 2 deletions(-)
▾Mwebclient/src/index.tsx
@@ -11,6 +11,37 @@ if (!(root instanceof HTMLElement)) {
"Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?",
);
}
function hasTouch() {
return (
"ontouchstart" in document.documentElement ||
navigator.maxTouchPoints > 0 ||
("msMaxTouchPoints" in navigator &&
typeof navigator.msMaxTouchPoints === "number" &&
navigator.msMaxTouchPoints > 0)
);
}
if (hasTouch()) {
// remove all the :hover stylesheets
try {
// prevent exception on browsers not supporting DOM styleSheets properly
for (const si in document.styleSheets) {
const styleSheet = document.styleSheets[si];
if (!styleSheet.cssRules) continue;
for (let ri = styleSheet.cssRules.length - 1; ri >= 0; ri--) {
const rule = styleSheet.cssRules[ri];
if (!("selectorText" in rule) || typeof rule.selectorText !== "string" || !rule.selectorText) continue;
if (rule.selectorText.match(":hover")) {
styleSheet.deleteRule(ri);
}
}
}
} catch {}
}
loadDataFromDB()
.then(() => {
root.innerHTML = "";
▾Mwebclient/src/style.css
@@ -47,13 +47,12 @@ option {
select:disabled {
background-color: var(--color-d);
color: oklch(0.50 0 0);
color: oklch(0.5 0 0);
&:hover {
background-color: var(--color-d);
}
}
button {
cursor: pointer;
&:disabled {