Skip to content

Instantly share code, notes, and snippets.

@kei-s
Forked from june29/Imagerotation.user.js
Created June 7, 2010 09:11
Show Gist options
  • Save kei-s/428422 to your computer and use it in GitHub Desktop.
Save kei-s/428422 to your computer and use it in GitHub Desktop.
Rotate Images (patched)
// ==UserScript==
// @name Rotate Images
// @namespace http://june29.jp/
// @include *
// ==/UserScript==
(function() {
var style = document.createElement('style');
document.body.appendChild(style);
style.textContent = "img, canvas, video {\n" + "-moz-transform: rotate(0deg);\n" + " }";
var offset = {};
window.addEventListener("MozOrientation", function(data) {
if (!offset.x) offset.x = data.x;
if (!offset.y) offset.y = data.y;
if (!offset.z) offset.z = data.z;
var radian = -1 * (data.x - offset.x) * 90;
style.sheet.cssRules[0].style.MozTransform = 'rotate(' + radian + 'deg)';
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment