Переглянути джерело

feat: add global viewport size css vars

Sv443 9 місяців тому
батько
коміт
dca17fa445
1 змінених файлів з 12 додано та 1 видалено
  1. 12 1
      src/index.ts

+ 12 - 1
src/index.ts

@@ -120,6 +120,7 @@ async function onDomLoad() {
   document.body.classList.add(`bytm-dom-${domain}`);
 
   try {
+    initGlobalCssVars();
     initObservers();
 
     await Promise.allSettled([
@@ -276,7 +277,7 @@ async function onDomLoad() {
   }
 }
 
-//#region insert css bundle
+//#region css
 
 /** Inserts the bundled CSS files imported throughout the script into a <style> element in the <head> */
 async function insertGlobalStyle() {
@@ -284,6 +285,16 @@ async function insertGlobalStyle() {
     error("Couldn't add global CSS bundle due to an error");
 }
 
+/** Initializes global CSS variables */
+function initGlobalCssVars() {
+  const applyVars = () => {
+    document.documentElement.style.setProperty("--bytm-viewport-height", `${window.innerHeight}px`);
+    document.documentElement.style.setProperty("--bytm-viewport-width", `${window.innerWidth}px`);
+  };
+  applyVars();
+  window.addEventListener("resize", applyVars);
+}
+
 //#region dev menu cmds
 
 /** Registers dev commands using `GM.registerMenuCommand` */