Mega.nz Swipe Gestures

Add swipe gestures to mega.nz.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Mega.nz Swipe Gestures
// @match       *://*.mega.nz/*
// @grant       none
// @version     1.1.1
// @author      NoUser
// @description Add swipe gestures to mega.nz.
// @namespace   https://greasyfork.org/en/scripts/459497-mega-nz-swipe-gestures
// @homepage    https://greasyfork.org/en/scripts/459497-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();
    }
  } else {
    // Check if the user has made a vertical swipe
    // Check if the user has swiped down
    // User has to swipe down at least 16 pixels for it to activate
    if (yDiff < -16) {
      document.querySelector('.v-btn.close').click();
    }
  }

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