Earlymanga Scripts

Allows L/R arrow key navigation between chapters & reize chapter images using / key.

  1. // ==UserScript==
  2. // @name Earlymanga Scripts
  3. // @namespace ew0345
  4. // @match *://earlymanga.org/manga/*/*
  5. // @grant none
  6. // @version 1.0
  7. // @author ew0345
  8. // @description Allows L/R arrow key navigation between chapters & reize chapter images using / key.
  9. // ==/UserScript==
  10. var chapterImages = ['.chapter-images-container-up img'];
  11. var chapterButtons = ['.prev-chapter', '.next-chapter'];
  12. var widthPercent = 100;
  13.  
  14. function resize() {
  15. var inp = prompt('Image Width / %\n\'autoh\' to fit images to page height,\n\'autow\' to fit images to page width.');
  16. widthPercent = inp.valueOf().toLowerCase();
  17.  
  18. if (widthPercent === "autow" || widthPercent === "w" || widthPercent === "fitw") {
  19. var pageWidth = document.body.clientWidth;
  20.  
  21. for (var i = 0; i < document.querySelectorAll(chapterImages).length; i++) {
  22. document.querySelectorAll(chapterImages)[i].style.width = pageWidth / document.querySelectorAll(chapterImages)[i].width * 100 + '%';
  23. }
  24. } else if (widthPercent === "autoh" || widthPercent === "h" || widthPercent === "fith" || widthPercent === "4koma") {
  25. var pageWidth = document.body.clientWidth;
  26. var pageHeight = window.height;
  27.  
  28. for (var i = 0; i < document.querySelectorAll(chapterImages).length; i++) {
  29. document.querySelectorAll(chapterImages)[i].style.width = pageWidth / document.querySelectorAll(chapterImages)[i].width * 100 + '%';
  30. document.querySelectorAll(chapterImages)[i].style.width = pageHeight / document.querySelectorAll(chapterImages)[i].height * 100 + '%';
  31. }
  32. } else if (widthPercent === 0) {
  33. return;
  34. } else {
  35. for (var i = 0; i < document.querySelectorAll(chapterImages).length; i++) {
  36. document.querySelectorAll(chapterImages)[i].style.width = widthPercent + '%';
  37. }
  38. }
  39. }
  40.  
  41. window.onkeydown = function(e) {
  42. switch (e.key) {
  43. case "ArrowLeft":
  44. document.querySelectorAll(chapterButtons[0]).length > 0 ? document.location = document.querySelectorAll(chapterButtons[0])[0].href : console.error('Already on first chapter.');
  45. break;
  46. case "ArrowRight":
  47. document.querySelectorAll(chapterButtons[1]).length > 0 ? document.location = document.querySelectorAll(chapterButtons[1])[0].href : console.error('Already on last chapter');
  48. break;
  49. case "/":
  50. resize();
  51. break;
  52. default:
  53. break;
  54. }
  55. }