Created
May 28, 2013 10:49
-
-
Save enigmaticape/5661933 to your computer and use it in GitHub Desktop.
Chrome extension to enable mouse wheel zooming. Click the middle button and use the wheel to zoom, increments of 20%. There's no options yet, and it cancels auto scroll and opening links in new tab with the middle click.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "Wheel Zoom", | |
"description": "Mouse Wheel Zooming.", | |
"version": "1.0", | |
"permissions": [ | |
"tabs", | |
"https://*/*", | |
"http://*/*" | |
], | |
"content_scripts": [{ | |
"all_frames": true, | |
"matches": [ | |
"http://*/*", | |
"https://*/*" | |
], | |
"js": ["wheelzoom.js"] | |
}] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zoomWithWheel = false; | |
zoomLevel = 1; | |
zoomIncrement = 0.2; | |
window.addEventListener("mousewheel", function( event ) { | |
if( zoomWithWheel ) { | |
if( event.wheelDeltaY > 0 ) { | |
zoomLevel += zoomIncrement; | |
} | |
if( event.wheelDeltaY < 0 ) { | |
zoomLevel -= zoomIncrement; | |
} | |
document.body.style.zoom = zoomLevel; | |
return false; | |
} | |
}, true ); | |
/* | |
Auto scroll listens for this event, so we | |
have to intercept it and cancel it | |
*/ | |
window.addEventListener("mousedown", function( event ) { | |
if(event.button == 1) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
}, true); | |
/* | |
Chrome listens for this event to trigger | |
open in new tab with middle click, it gets | |
a bit confusing to mix and match, so we | |
have to intercept and cancel that also | |
*/ | |
window.addEventListener("click", function( event ) { | |
if(event.button == 1){ | |
event.preventDefault(); | |
event.stopPropagation(); | |
} | |
}, true); | |
/* | |
And finally, we can stick our own event listener | |
on mouseup and off we jolly well go, eh ? | |
*/ | |
window.addEventListener("mouseup", function( event ) { | |
if(event.button == 1){ | |
event.preventDefault(); | |
event.stopPropagation(); | |
zoomWithWheel = !zoomWithWheel; | |
} | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment