Enlarge all p tags on a page with AltGr+p (reset with AltGr-o)
当前为
// ==UserScript==
// @name Enhance!
// @namespace meyerk.com
// @match *://*/*
// @grant none
// @version 1.1
// @author MeyerK
// @description Enlarge all p tags on a page with AltGr+p (reset with AltGr-o)
// ==/UserScript==
class enhance
{
constructor()
{
this.isRightAltKey = false;
this.zoomInc = 3;
this.currentZoomStep = 0;
this.maxZoomSteps = 6;
}
toggleAltGr(ev)
{
if ((ev.key == 'AltGraph') && (ev.location == 2))
{
this.isRightAltKey = (ev.type == 'keydown') ? true : false;
}
}
zoom(ev)
{
var pElems = null;
var i = 0;
var newSize = 0;
if (this.isRightAltKey)
{
if (ev.which == 80)
{
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
{
newSize = originalSize + this.zoomInc + 'px';
}
pElems[i].style.fontSize = newSize;
}
}
if (ev.which == 79)
{
pElems = document.querySelectorAll('p');
this.currentZoomStep = 0;
for (i=0; i<pElems.length; i++)
{
pElems[i].style.fontSize = '';
}
}
}
}
}
var e = new enhance();
document.addEventListener('keydown', e.toggleAltGr.bind(e));
document.addEventListener('keyup', e.toggleAltGr.bind(e));
document.addEventListener('keyup', e.zoom.bind(e));