// ==UserScript==
// @name           ExpandOwlyURL
// @namespace      http://d.hatena.ne.jp/send/
// @description    expand ow.ly URL
// @include        *
// @require        http://gist.github.com/3238.txt#$X
// ==/UserScript==

(function() {
  $X("//a[starts-with(@href, 'http://ow.ly/')]", document).forEach(function(anchor) {
    var timer = setTimeout(function() {
      if (timer) clearTimeout(timer);
      GM_xmlhttpRequest({
        method: 'GET',
        url: anchor.getAttribute('href'),
        onload: function(xhr) {
          var dom = createDocument(xhr.responseText);
          var iframe = dom.getElementById('hootFrame');
          if (!iframe) return;
          anchor.setAttribute('href', iframe.getAttribute('src'));
        }
      });
    },0);
  });

  // this function from AutoPagerize
  function createDocument(str) {
    if (document.documentElement.nodeName != 'HTML') 
      return new DOMParser().parseFromString(str, 'application/xhtml+xml');
    var html = str.replace(/^[\s\S]*?<html(?:[ \t\r\n][^>]*)?>|<\/html[ \t\r\n]*>[\w\W]*$/ig, '');
    var doc = document.implementation.createDocument(null, 'html', null);
    var range = document.createRange();
    range.setStartAfter(document.body);
    var fragment = range.createContextualFragment(html);
    try {
      fragment = doc.adoptNode(fragment);
    } catch (e) {
      fragment = doc.importNode(fragment, true);
    }
    doc.documentElement.appendChild(fragment);
    return doc;
  }
  
})();

@@ -236,16 +236,44 @@
 ion() %7B%0A
+  setTimeout(function() %7B%0A  
   $X(%22//
@@ -350,24 +350,26 @@
 chor) %7B%0A    
+  
 var timer = 
@@ -388,24 +388,26 @@
 unction() %7B%0A
+  
       if (ti
@@ -438,16 +438,18 @@
 ;%0A      
+  
 GM_xmlht
@@ -460,16 +460,18 @@
 quest(%7B%0A
+  
         
@@ -493,16 +493,18 @@
         
+  
 url: anc
@@ -529,16 +529,18 @@
 href'),%0A
+  
         
@@ -569,24 +569,26 @@
 %7B%0A          
+  
 var dom = cr
@@ -615,24 +615,26 @@
 ponseText);%0A
+  
           va
@@ -683,24 +683,26 @@
 ;%0A          
+  
 if (!iframe)
@@ -710,16 +710,18 @@
 return;%0A
+  
         
@@ -783,26 +783,30 @@
 ));%0A        
-%7D%0A
+  %7D%0A  
       %7D);%0A  
@@ -811,20 +811,31 @@
     
+  
 %7D,0);%0A
+  
   %7D);%0A
+  %7D,0);
 %0A  /

use setTimeout