Changeset 10413

Show
Ignore:
Timestamp:
04/25/08 12:21:35 (7 months ago)
Author:
mattn
Message:

* token対応

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/reblogcommand.user.js

    r8961 r10413  
    1616// Reblog 
    1717// ---------------------------------------------------------------------------- 
     18 
     19function isTumblrDashboardURL(url){ 
     20        return url.match("^http://www\.tumblr\.com/dashboard.*$"); 
     21} 
    1822 
    1923function isTumblrUserURL(url){ 
     
    3236} 
    3337 
    34 function getURLByID(id){ 
     38function getURLByID(id, token){ 
     39        if (token) return "http://www.tumblr.com/reblog/" + id + "/" + token + "?redirect_to=/dashboard"; 
    3540        return "http://www.tumblr.com/reblog/" + id; 
    3641} 
    3742 
    38 function getSource(url){ 
    39         with(D()){ 
    40                 return xhttp.get(url) 
    41         } 
     43// copy from tombloo 
     44function unescapeHTML(s){ 
     45        return s.replace( 
     46                /&/g, '&').replace( 
     47                /"/g, '"').replace( 
     48                /&lt;/g, '<').replace( 
     49                /&gt;/g, '>'); 
     50} 
     51 
     52// copy from tombloo 
     53function getReblogToken(url){ 
     54        url = unescapeHTML(url); 
     55        if(url.match(/&pid=(.*)&rk=(.*)/) || url.match('/reblog/(.*?)/([^\\?]*)')) 
     56                return { 
     57                        id    : RegExp.$1, 
     58                        token : RegExp.$2, 
     59                } 
    4260} 
    4361 
     
    8098} 
    8199 
    82 function postData(url, aData){ 
    83         with(D()){ 
    84                 return xhttp.post(url, aData) 
    85         } 
    86 } 
    87  
    88100function reblog(aURL){ 
    89101        var id  = getIDByPermalink(aURL); 
     
    96108                } 
    97109        } 
    98         var url = getURLByID(id); 
    99110        window.Minibuffer.status('ReblogCommand'+id, 'Reblog ...'); 
    100         getSource(url). 
     111        d = D(); 
     112        var url = aURL; 
     113        d.xhttp.get(url). 
    101114        next(function(res){ 
    102                 return postData(url, createPostData( parseParams( convertToHTMLDocument(res.responseText)))); 
     115                var token = getReblogToken(res.responseText.match('iframe src="(.*?)"')[1]); 
     116                url = getURLByID(token.id, token.token) 
     117                return d.xhttp.get(url); 
     118        }). 
     119        next(function(res){ 
     120                return d.xhttp.post(url, createPostData( parseParams( convertToHTMLDocument(res.responseText)))); 
    103121        }). 
    104122        next(function(){ window.Minibuffer.status('ReblogCommand'+id, 'Reblog ... done.', 100); d.call()}). 
    105123        error(function(){ 
    106                 if(confirm('reblog manually ? \n' + url)) reblogManually(aURL); 
     124                if(confirm('reblog manually ? \n' + url)) reblogManually(url); 
    107125                d.call(); 
    108126        }); 
     
    162180          var urls = []; 
    163181          if(!stdin.length){ 
    164                   // command line is just 'reblog' 
    165                   urls = [window.location.href]; 
     182                  if(isTumblrDashboardURL(window.location.href.toString())){ 
     183                        link = window.Minibuffer.execute('current-link'); 
     184                        if (link) urls = [link.toString()]; 
     185                  }else{ 
     186                        // command line is just 'reblog' 
     187                        urls = [window.location.href]; 
     188                  } 
    166189          }else if(stdin.every(function(a){return typeof a == 'string'})){ 
    167190                  // command line is 'location | reblog'