Source: site.view [edit]
Function name: convertBitlyUrls
Arguments:
Description: Convert bitly links into regular links
Page type: webl
Render function:  
Module: perfectCartoon

Page source:

   var P = GetURL("https://docs.google.com/spreadsheet/pub?key=0AsUaQihpzloZdEJXbkc0Y2pSS1VRX180aEVlaEdwTkE&output=html");

   var numDocs = 0;
   var PAGE=1;
   var IMG=2;
   var TITLE=3;
   var TEXT=4;
   var AUTHOR=5;
   var TAGS=6;
   var SCORE=7;


   var cln2 = fun(s)
      s = ExpandCharEntities(Str_Trim(s));
      s = Wub_ReplaceAll(s, "\t", " ");
      s = Wub_ReplaceAll(s, "\\", "");
      s = Wub_ReplaceAll(s, "???", "");
      s = Wub_ReplaceAll(s, "??", "");
      s = Wub_ReplaceAll(s, ",", " ");
      return s;
   end;
  
   var cln = fun(s)
      return cln2(Text(s));
   end;

     
var main = fun()     
   var res = "";

   every tr in Elem(P, "tr") do
     if numDocs > 30000 then
        return res;
     end;
       
     var dir = tr.dir ? nil;
     if (dir == "ltr") then
        var tds = Elem(P, "td") inside tr;
        if (Size(tds) == TAGS+1) or (Size(tds) == SCORE+1) or (Size(tds) == SCORE+2) then
  
           var s = cln(tds[PAGE]);
           if (s != "") and (s != "pageUrl") then
              if (Str_IndexOf("bit.ly", s) > 0) then                 

     			 var B = GetURL("http://www.internetofficer.com/seo-tool/redirect-check?url=" + s);
                 var E = Elem(B, "b") directlyafter Pat(B, "Redirected to");
     	         if Size(E) == 1 then
                    res = res + Str_Trim(Text(E[0])) + "\n";
                 else 
        			res = res + s + "\n"
                 end;
                 numDocs = numDocs + 1; 
              else
     			 res = res + s + "\n"
              end;
           end
        end
     end
   end;          
     
   return res;
     
end;
     
main();