Преглед изворни кода

fix: update numKeysJumpTo script

Sv443 пре 1 година
родитељ
комит
396929a5f5
1 измењених фајлова са 30 додато и 6 уклоњено
  1. 30 6
      src/dev/numKeysJumpTo.js

+ 30 - 6
src/dev/numKeysJumpTo.js

@@ -1,26 +1,41 @@
 (() => {
 (() => {
-  const timeSteps = 9; // excluding 0
+  const timeSteps = 10; // includes 10 so the 9 key doesn't jump to the very end
   function getX(timeKey, maxWidth) {
   function getX(timeKey, maxWidth) {
     if(timeKey >= timeSteps)
     if(timeKey >= timeSteps)
       return maxWidth;
       return maxWidth;
     return Math.floor(maxWidth / timeSteps) * timeKey;
     return Math.floor(maxWidth / timeSteps) * timeKey;
   }
   }
 
 
-  console.log("scrollY", window.scrollY);
+  console.log("scrollY", getUnsafeWindow().scrollY);
 
 
-  const elem = document.querySelector("tp-yt-paper-progress#sliderBar");
+  const elem = document.querySelector("tp-yt-paper-slider#progress-bar tp-yt-paper-progress#sliderBar");
   const rect = getOffset(elem);
   const rect = getOffset(elem);
-  const x = getX(1, rect.width);
+
+  console.log("element rect", rect);
+
+  const x = getX(9, rect.width);
   const y = rect.top - rect.height / 2;
   const y = rect.top - rect.height / 2;
 
 
-  console.log(x, y, rect);
+  console.log("x & y", x, y);
 
 
   const evt = new MouseEvent("mousedown", {
   const evt = new MouseEvent("mousedown", {
     clientX: x,
     clientX: x,
     clientY: y,
     clientY: y,
+    layerX: x,
+    layerY: rect.height / 2,
     target: elem,
     target: elem,
     bubbles: true,
     bubbles: true,
-    view: window,
+    view: getUnsafeWindow(),
+    shiftKey: false,
+    ctrlKey: false,
+    altKey: false,
+    metaKey: false,
+    button: 0,
+    buttons: 1,
+    which: 1,
+    isTrusted: true,
+    offsetX: 0,
+    offsetY: 0,
   });
   });
 
 
   elem.dispatchEvent(evt);
   elem.dispatchEvent(evt);
@@ -38,3 +53,12 @@
     return { top: _y, left: _x, width: rect.width, height: rect.height };
     return { top: _y, left: _x, width: rect.width, height: rect.height };
   }
   }
 })();
 })();
+
+function getUnsafeWindow() {
+  try {
+    return unsafeWindow;
+  }
+  catch(e) {
+    return window;
+  }
+}