Greasy Fork

Mega.nz Swipe Gestures

Add swipe gestures to mega.nz.

目前为 2023-02-06 提交的版本。查看 最新版本

// ==UserScript==
// @name        Mega.nz Swipe Gestures
// @match       *://*mega.nz/*
// @grant       none
// @version     1.0.0
// @author      NoUser
// @description Add swipe gestures to mega.nz.
// @namespace   Mega.nz Swipe Gestures
// @homepage    Mega.nz Swipe Gestures
// @license     MIT
// ==/UserScript==

  // Add touch event listeners to the document
  document.addEventListener('touchstart', handleTouchStart, false);
  document.addEventListener('touchmove', handleTouchMove, false);

  // Variables to keep track of touch events
  var xDown = null;
  var yDown = null;

  function handleTouchStart(evt) {
    xDown = evt.touches[0].clientX;
    yDown = evt.touches[0].clientY;
  }

  function handleTouchMove(evt) {
    if (!xDown || !yDown) {
      return;
    }

    var xUp = evt.touches[0].clientX;
    var yUp = evt.touches[0].clientY;
    var xDiff = xDown - xUp;
    var yDiff = yDown - yUp;

    // Check if the user has made a horizontal swipe
    if (Math.abs(xDiff) > Math.abs(yDiff)) {
      // Check if the user has swiped right
      if (xDiff > 0) {
        document.querySelector('.gallery-btn.next').click();
      }
      // Check if the user has swiped left
      else {
        document.querySelector('.gallery-btn.previous').click();
      }
    }

    // Reset values
    xDown = null;
    yDown = null;
}