Advertisement
AHOHNMYC

Листалка

Apr 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Листалка
  3. // @namespace    AHOHNMYC_world
  4. // @version      0.0.0.0
  5. // @description  Doesn't exists
  6. // @author       Me
  7. // @match        http://hpmor.ru/book/1/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. addEventListener('keyup', e => {
  12.     if (!e.ctrlKey)
  13.         return;
  14.     if (e.key == 'ArrowLeft')
  15.         prevPage();
  16.     if (e.key == 'ArrowRight')
  17.         nextPage();
  18. });
  19.  
  20. function nextPage() {
  21.     gotoDelta(n => n+1)
  22. }
  23.  
  24. function prevPage() {
  25.     gotoDelta(n => n-1)
  26. }
  27.  
  28. function gotoDelta(callback) {
  29.     const chapterRegEx = /^(http?:\/\/hpmor\.ru\/book\/1\/)(\d+)(\/)$/;
  30.     if (!chapterRegEx.test(location))
  31.         return;
  32.     let [, prefix, chapter, postfix] = location.toString().match(chapterRegEx);
  33.     chapter = callback(+chapter)
  34.     window.location = prefix + chapter + postfix;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement