Greasy Fork镜像 is available in English.

Enhance

Enlarge all p tags on a page with AltGr+p (reset with AltGr-o) - basically, zooms just the text on text-heavy pages without the rest of the page.

22.05.2020 itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name        Enhance
// @namespace   meyerk.com
// @match       *://*/*
// @grant       none
// @version     1.3
// @author      MeyerK
// @description Enlarge all p tags on a page with AltGr+p (reset with AltGr-o) - basically, zooms just the text on text-heavy pages without the rest of the page.
// ==/UserScript==

class enhance
{
  constructor()
  {
    this.rightAltKeyIsOn = false;
    this.zoomInc = 3;
    this.currentZoomStep = 0;
    this.maxZoomSteps = 6;
  }
  
  toggleAltGr(ev)
  {
    if (ev.code == 'AltRight')
    {
      this.rightAltKeyIsOn = (ev.type == 'keydown') ? true : false; 
    }    
  }
  
  do(ev)
  {        
    if (this.rightAltKeyIsOn)
    {
      if (ev.code == 'KeyP')
      {
        this.currentZoomStep = (this.currentZoomStep < this.maxZoomSteps) ? this.currentZoomStep + 1 : 0;
        this.setFontSize();
      }
      
      if (ev.code == 'KeyO')
      {
        this.currentZoomStep = 0;
        this.setPropertyOfPs('fontSize', ''); 
      }
      
      if (ev.code == 'KeyB')
      {
        this.setPropertyOfPs('color', 'black'); 
      }
    }
  }
  
  setFontSize()
  {
    var newSize = null;
    var originalSize = null;
    var pElems = document.querySelectorAll('p');
    var i = 0;
    
    for (i=0; i<pElems.length; i++)
    {
      originalSize = parseInt(window.getComputedStyle(pElems[i]).fontSize, 10);

      if (this.currentZoomStep === 0)
      {
        newSize = '';
      }
      else
      {
        newSize = originalSize + this.zoomInc + 'px';
      }

      pElems[i].style.fontSize = newSize;
    }    
  }
    
  setPropertyOfPs(propName, val)
  {
    var i = 0;
    var pElems = null;
    
    pElems = document.querySelectorAll('p');
    for (i=0; i<pElems.length; i++)
    {
      pElems[i].style[propName] = val;
    }    
  }
}

var e = new enhance();
document.addEventListener('keydown', e.toggleAltGr.bind(e));
document.addEventListener('keyup',   e.toggleAltGr.bind(e));
document.addEventListener('keyup',   e.do.bind(e));
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元