browser-resize.js 898 B

12345678910111213141516171819202122232425262728
  1. (() => {
  2. // const isMobile =
  3. // /(iPhone|iPad|iPod|iOS|Android|Linux armv8l|Linux armv7l|Linux aarch64)/i.test(
  4. // navigator.platform
  5. // );
  6. const isMobile =
  7. /(iPhone|iPad|iPod|iOS|Android|Linux armv8l|Linux armv7l|Linux aarch64)/i.test(
  8. navigator.userAgent
  9. );
  10. function resize() {
  11. const path = location.pathname;
  12. if (isMobile && !path.includes("mobile")) {
  13. location.href = location.href.replace(".html", "-mobile.html");
  14. }
  15. if (!isMobile && path.includes("mobile")) {
  16. location.href = location.href.replace("-mobile.html", ".html");
  17. }
  18. const htmlStyle = document.querySelector("html").style;
  19. htmlStyle.fontSize =
  20. (isMobile
  21. ? window.screen.availWidth / 375
  22. : window.innerWidth / window.screen.availWidth) *
  23. 16 +
  24. "px";
  25. }
  26. resize();
  27. window.addEventListener("resize", () => resize());
  28. })();