Enhance!

Enlarge all p tags on a page with AltGr+p (reset with AltGr-o)

当前为 2020-05-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Enhance!
  3. // @namespace meyerk.com
  4. // @match *://*/*
  5. // @grant none
  6. // @version 1.1
  7. // @author MeyerK
  8. // @description Enlarge all p tags on a page with AltGr+p (reset with AltGr-o)
  9. // ==/UserScript==
  10.  
  11. class enhance
  12. {
  13. constructor()
  14. {
  15. this.isRightAltKey = false;
  16. this.zoomInc = 3;
  17. this.currentZoomStep = 0;
  18. this.maxZoomSteps = 6;
  19. }
  20. toggleAltGr(ev)
  21. {
  22. if ((ev.key == 'AltGraph') && (ev.location == 2))
  23. {
  24. this.isRightAltKey = (ev.type == 'keydown') ? true : false;
  25. }
  26. }
  27. zoom(ev)
  28. {
  29. var pElems = null;
  30. var i = 0;
  31. var newSize = 0;
  32. if (this.isRightAltKey)
  33. {
  34. if (ev.which == 80)
  35. {
  36. pElems = document.querySelectorAll('p');
  37. this.currentZoomStep = (this.currentZoomStep < this.maxZoomSteps) ? this.currentZoomStep + 1 : 0;
  38.  
  39. for (i=0; i<pElems.length; i++)
  40. {
  41. var originalSize = parseInt(window.getComputedStyle(pElems[i]).fontSize, 10);
  42.  
  43. if (this.currentZoomStep === 0)
  44. {
  45. newSize = '';
  46. }
  47. else
  48. {
  49. newSize = originalSize + this.zoomInc + 'px';
  50. }
  51.  
  52. pElems[i].style.fontSize = newSize;
  53. }
  54. }
  55.  
  56. if (ev.which == 79)
  57. {
  58. pElems = document.querySelectorAll('p');
  59. this.currentZoomStep = 0;
  60.  
  61. for (i=0; i<pElems.length; i++)
  62. {
  63. pElems[i].style.fontSize = '';
  64. }
  65. }
  66. }
  67. }
  68. }
  69.  
  70. var e = new enhance();
  71. document.addEventListener('keydown', e.toggleAltGr.bind(e));
  72. document.addEventListener('keyup', e.toggleAltGr.bind(e));
  73. document.addEventListener('keyup', e.zoom.bind(e));