Arrow keys for browsing manga

Allows you to use arrow keys to navigate the site

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Arrow keys for browsing manga
// @namespace   Violentmonkey Scripts
// @match       https://manganato.com/*
// @match       https://mangakakalot.com/*
// @grant       none
// @version     1.1
// @author      Ost
// @description Allows you to use arrow keys to navigate the site
// ==/UserScript==

// for &
function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes[0].nodeValue;
}


var regex = /href="([^"]*)/gm;
//var regex = /.*/gm;

var doc = document.getElementsByClassName('group-page')
if (!doc.length){
  var doc = document.getElementsByClassName('group_page')
}
doc = doc[0].innerHTML

var elements = [...doc.matchAll(regex)];

var prev = htmlDecode(elements[elements.length-4][1]);
var next = htmlDecode(elements[elements.length-3][1]);

document.addEventListener("keydown", keyDownTextField, false);

  function keyDownTextField(e) {
      var search = document.getElementsByClassName("searchinput")[0];
      if (document.activeElement !== search) {
          switch (e.which) {
              case 37: // "Arrow Left"
                  console.log('left');
                  window.location.href = prev;
                  break;
              case 39: // "Arrow Right"
                  window.location.href = next;
                  break;
              default:
                  return; // exit this handler for other keys
          }
          e.preventDefault(); // prevent the default action
      } else if (e.which == 32) {
          search.value += " ";
          e.preventDefault();
      }
      return;
  }