Google Play app details images scroll arrow keys

assign horizontal arrow keys to scroll app image previews in page and overlay

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Google Play app details images scroll arrow keys
// @namespace   Violentmonkey Scripts
// @match       https://play.google.com/store/apps/details*
// @grant       none
// @version     1.3
// @author      You
// @description assign horizontal arrow keys to scroll app image previews in page and overlay
// ==/UserScript==


window.addEventListener("keydown", function (event) {
  if (event.defaultPrevented) {
    return; // Do nothing if the event was already processed
  }

  switch (event.key) {
    case "Left": // IE/Edge specific value
    case "ArrowLeft":
		  var left = document.querySelector('[jsaction="click:E7ORLb"]');
		  if (left != null) {
			left.click()
			break;
		  }
		  var scrollleft = document.querySelector('[jsname="PjUZJf"]')
		  triggerMouseEvent(scrollleft, "mousedown"); triggerMouseEvent(scrollleft, "mouseup");
      break;
    case "Right": // IE/Edge specific value
    case "ArrowRight":
   		  var right = document.querySelector('[jsaction="click:tJiF1e"]');
   		  if (right != null) {
			right.click()
			break;
		  }

		  var scrollright = document.querySelector('[jsname="kZCROc"]')
		  triggerMouseEvent(scrollright, "mousedown"); triggerMouseEvent(scrollright, "mouseup"); 
      break;
    default:
      return; // Quit when this doesn't handle the key event.
  }

  // Cancel the default action to avoid it being handled twice
  event.preventDefault();
}, true);

function triggerMouseEvent (node, eventType) {
    var clickEvent = document.createEvent ('MouseEvents');
    clickEvent.initEvent (eventType, true, true);
    node.dispatchEvent (clickEvent);
}