Skip to content

Instantly share code, notes, and snippets.

@felipenmoura
Created October 14, 2016 21:43
Show Gist options
  • Save felipenmoura/f7282542e967f86f6aba887b5f622a41 to your computer and use it in GitHub Desktop.
Save felipenmoura/f7282542e967f86f6aba887b5f622a41 to your computer and use it in GitHub Desktop.
Use this to visualize the vibration result from the navigator.vibrate api.
(function (){
const originalVibrate = navigator.vibrate;
navigator.vibrate = function(){
var timer = 0;
var _b = document.body || false;
var curToggleStatus = true;
var previousBodyBorder = _b.style.border || 'none';
function toggle (force) {
if(!_b) return;
if(curToggleStatus && !force){
_b.style.border = 'solid 3px red';
}else{
_b.style.border = previousBodyBorder;
}
curToggleStatus = !curToggleStatus;
}
(arguments[0] || []).forEach(function(cur){
setTimeout(toggle, timer);
timer+= cur;
});
setTimeout(function(){toggle(true);}, ++timer);
return originalVibrate.apply(navigator, arguments);
}
})();
/*
// plays the imperial march
window.navigator.vibrate([500, 200, 500, 200, 500,
200, 100, 200, 100, 200, 500,
200, 100, 200, 100, 200, 500
]);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment