Enhance!

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

目前为 2020-05-16 提交的版本。查看 最新版本

// ==UserScript==
// @name        Enhance!
// @namespace   meyerk.com
// @match       *://*/*
// @grant       none
// @version     1.0
// @author      MeyerK
// @description Enlarge all p tags on a page with Alt+p (reset with Alt-o)
// ==/UserScript==

class enhance
{
  constructor()
  {
    this.zoomInc = 3;
    this.currentZoomStep = 0;
    this.maxZoomSteps = 6;
  }
  
  zoom(ev)
  {
    var pElems = null;
    var i = 0;
    
    if ((ev.which == 80) && (ev.altKey === true))
    {
      pElems = document.querySelectorAll('p');
      this.currentZoomStep = (this.currentZoomStep < this.maxZoomSteps) ? this.currentZoomStep + 1 : 0;
      
      for (i=0; i<pElems.length; i++)
      {
        var originalSize = parseInt(window.getComputedStyle(pElems[i]).fontSize, 10);
        
        if (this.currentZoomStep === 0)
        {
          newSize = '';
        }
        else
        {
          var newSize = originalSize + this.zoomInc + 'px';
        }
        
        pElems[i].style.fontSize = newSize;
      }
    }

    if ((ev.which == 79) && (ev.altKey === true))
    {
      pElems = document.querySelectorAll('p');
      this.currentZoomStep = 0;
      
      for (i=0; i<pElems.length; i++)
      {
        pElems[i].style.fontSize = '';
      }
    }
  }
}

var e = new enhance();
document.addEventListener('keyup', e.zoom.bind(e));