Skip to content

Instantly share code, notes, and snippets.

@cat-in-136
Created March 19, 2012 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cat-in-136/2112138 to your computer and use it in GitHub Desktop.
Save cat-in-136/2112138 to your computer and use it in GitHub Desktop.
Web Vibrator (R18?) (ウェブバイブ; たぶん18禁)
<!DOCTYPE html>
<!-- Android版Firefoxなどでご利用ください。 -->
<html>
<head>
<meta charset="UTF-8" />
<meta name="rating" content="adult" />
<title>Wrong use of Vibration API (R18?) (Vibration APIの間違った使い方; たぶん18禁)</title>
<script type="text/javascript">
var WebVibrator = {
mode: 0,
timerId: -1,
PATTERN: [
[0], // Power off.
[150, 350, 150, 350],
[250, 250, 250, 250],
[125, 125, 125, 125, 125, 125, 125, 125]
],
getPattern: function() {
var pattern = {};
pattern.pattern = WebVibrator.PATTERN[WebVibrator.mode];
pattern.interval = 0;
for (var i = 0; i < pattern.pattern.length; i++) {
pattern.interval += pattern.pattern[i];
}
return pattern;
},
getVibrateFunc: function () {
var vibrate = function() {};
if (navigator.vibrate) vibrate = function(p) {navigator.vibrate(p);}
if (navigator.mozVibrate) vibrate = function(p) {navigator.mozVibrate(p);}
if (navigator.webkitVibrate) vibrate = function(p) {navigator.webkitVibrate(p);}
return vibrate;
},
switchOff: function () {
WebVibrator.update(-1000);
},
update: function (updown) {
var mode = WebVibrator.mode + updown;
mode = Math.max(0, Math.min(WebVibrator.PATTERN.length-1, mode));
WebVibrator.mode = mode;
if (WebVibrator.timerId != -1) {
window.clearInterval(WebVibrator.timerId);
WebVibrator.timerId = -1;
}
var pattern = WebVibrator.getPattern();
var vibrate = WebVibrator.getVibrateFunc();
if (pattern.interval != 0) {
WebVibrator.timerId = window.setInterval(function(){
vibrate(pattern.pattern);
}, pattern.interval);
} else {
vibrate(pattern.pattern);
}
document.getElementById("mode").innerHTML = ""+mode;
}
};
</script>
<style type="text/css">
html, body { background-color: #af0000; color: #fff; }
#mode, button { font-size: 64px; }
.notice { }
</style>
</head>
<body>
<div><output id="mode">0</output></div>
<div>
<button onclick="WebVibrator.update(+1)">+1</button>
<button onclick="WebVibrator.update(-1)">-1</button>
<button onclick="WebVibrator.switchOff()">STOP</button>
</div>
<div class="notice">
※本品はジョークグッズです。
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment