您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
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));