Created
February 10, 2010 04:44
-
-
Save hitode909/300034 to your computer and use it in GitHub Desktop.
ノートパソコンを縦にするとページが回転する
This file contains 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
// ==UserScript== | |
// @name kurukuruwindow | |
// @namespace http://www.hatena.ne.jp/hitode909 | |
// @include * | |
// ==/UserScript== | |
(function() { | |
try { if (window != window.parent) return } catch(e) { return }; | |
var lowPass = { x: 0.0, y: 0.0, z: 0.0 }; | |
var currentRad = 0; | |
var scrollRate = 10; | |
window.addEventListener( | |
"MozOrientation", | |
function(data) { | |
var xyz = ['x', 'y', 'z']; | |
for(var i = 0;i<xyz.length;i++){ | |
var axis = xyz[i]; | |
lowPass[axis] = data[axis] * 0.3 + lowPass[axis] * 0.7; | |
} | |
var lastRad = currentRad; | |
var atan = Math.atan(lowPass.x / lowPass.z) + (lowPass.z > 0 ? 0 : Math.PI); | |
// each 90 deg is nice. | |
var newRad = atan = Math.round(atan / (Math.PI/2)) * (Math.PI/2); | |
currentRad = currentRad * 0.5 + newRad * 0.5; | |
if (Math.abs(currentRad - newRad) < 0.05) currentRad = newRad; | |
var deg = currentRad * -180 / Math.PI | |
var rate = Math.abs(Math.cos(currentRad)); // normal = 1 ~ side = 0 | |
var scale = rate + (window.innerHeight / window.innerWidth) * (1-rate); | |
// rotate, scale | |
window.document.body.style.MozTransform = 'rotate(' + deg + 'deg) scale(' + scale + ')'; | |
if (currentRad != lastRad) { | |
// transform origin | |
var origin = '' + (window.innerWidth + window.scrollX * 2) * 100 / (window.document.body.offsetWidth * 2) + | |
'% ' + (window.innerHeight + window.scrollY * 2) * 100 / (window.document.body.offsetHeight * 2) + '%'; | |
window.document.body.style.MozTransformOrigin = origin; | |
} | |
}, | |
true); | |
window.addEventListener( | |
"DOMMouseScroll", | |
function scroll(event){ | |
if (Math.abs(Math.sin(currentRad)) < 0.5) return; | |
var dx = Math.sin(currentRad) * event.detail; | |
var dy = Math.cos(currentRad) * event.detail; | |
window.scrollBy(dx * scrollRate, dy * scrollRate); | |
event.preventDefault(); | |
}, | |
true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment