Skip to content

Instantly share code, notes, and snippets.

@jamesu
Created October 10, 2009 19:29
Show Gist options
  • Save jamesu/207094 to your computer and use it in GitHub Desktop.
Save jamesu/207094 to your computer and use it in GitHub Desktop.
// Bookmarklet to read "title" hints on an iPhone
// Usage: Run boomarklet.
// Using two fingers, hold down on your desired image and await the hint popup.
//
// Code:
function registerImg(img) {
var timer = null;
function ts(e) {
if (e.touches.length < 2)
return;
e.preventDefault();
timer = setTimeout(function(){alert(img.getAttribute("title"));},500);
}
function te(e) {
e.preventDefault();
clearTimeout(timer);
}
img.ontouchstart = ts;
img.ontouchend = img.ontouchcancel = te;
}
var i,imgs = document.querySelectorAll("img");
for (i=0;i<imgs.length;i++) registerImg(imgs[i]);
// In bookmarklet form:
javascript:function%20registerImg(img)%20{var%20timer%20=%20null;function%20ts(e)%20{if%20(e.touches.length%20<%202)return;e.preventDefault();timer%20=%20setTimeout(function(){alert(img.getAttribute(%22title%22));},500);}function%20te(e)%20{e.preventDefault();clearTimeout(timer);}img.ontouchstart%20=%20ts;img.ontouchend%20=%20img.ontouchcancel%20=%20te;}var%20i,imgs%20=%20document.querySelectorAll(%22img%22);for%20(i=0;i<imgs.length;i++)%20registerImg(imgs[i]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment