Greasy Fork

Keyboard Page Up/Down

Use key (PgUp: ← D P Ctrl+Shift+Space; PgDn: → F N Ctrl+Space) to click the privious or next button on the page.

目前为 2021-01-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Keyboard Page Up/Down
// @name:zh      键盘翻页
// @description       Use key (PgUp: ← D P Ctrl+Shift+Space; PgDn: → F N Ctrl+Space) to click the privious or next button on the page.
// @description:zh    使用键盘按键(PgUp: ← D P Ctrl+Shift+Space; PgDn: → F N Ctrl+Space) 点击页面上的上一页/下一页
// @namespace    keybordPageUpDown.userscript
// @version      0.1
// @description  使用键盘翻页(PgUp: ← D P Ctrl+Shift+Space; PgDn: → F N Ctrl+Space)
// @author       h
// @match        https://yande.re/*
// @match        https://konachan.com/*
// @match        https://*.iwara.tv/*
// @match        https://*.javlibrary.com/*
// @match        https://adnmb3.com/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  window.addEventListener('keyup', function(e){
    let s;
    switch(e.keyCode){
      case 32: // Space
        if(e.ctrlKey && !e.metaKey) s = e.shiftKey ? 1 : 2;
        break;
      case 37: // ←
      case 68: // D
      case 80: // P
      case 33: // PgUp
        s = 1;
        break;
      case 39: // →
      case 70: // F
      case 78: // N
      case 34: // PgDn
        s = 2;
        break;
    }
    if (s) {
      const m = {
        "https://yande\.re/post/popular.*": {"btn": ['#post-popular > h3 > a:nth-child(1)', '#post-popular > h3 > a:nth-child(2)'], "ignore_id": ["tags"]},
        "https://yande\.re/.*": {"btn":['a.previous_page', 'a.next_page'], "ignore_id": ["tags"]},
        "https://konachan.com/.*": {"btn": ['a.previous_page', 'a.next_page']},
        "https://.*\.iwara\.tv/.*": {"btn": ['.pager-previous > a', '.pager-next > a']},
        "https://(.*\.)?javlibrary\.com/.*": {"btn": ['a.page.prev', 'a.page.next']},
        "https://adnmb[0-9]?\.com/.*": {"btn": ['#h-content > div.uk-container > ul > li:nth-child(1) > a', '#h-content > div.uk-container > ul > li:nth-last-child(2) > a'], "ignore": "textarea, input, select, button"},
      };

      let u = window.location.href;
      let k = Object.keys(m).find(k => u.match(k));
      if (!k) return;
      let t = m[k];

      let ae = document.activeElement;
      if (ae && t.ignore_id && t.ignore_id.find(i => ae === document.getElementById(i))) return;
      if (ae && t.ignore && [...document.querySelectorAll(t.ignore)].find(i => i.contains(ae))) return;

      let a = document.querySelector(t.btn[s-1]);
      if (a){ a.click(); return; }
    }
  });
})();