Changeset 10413
- Timestamp:
- 04/25/08 12:21:35 (7 months ago)
- Files:
-
- 1 modified
-
lang/javascript/userscripts/reblogcommand.user.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/reblogcommand.user.js
r8961 r10413 16 16 // Reblog 17 17 // ---------------------------------------------------------------------------- 18 19 function isTumblrDashboardURL(url){ 20 return url.match("^http://www\.tumblr\.com/dashboard.*$"); 21 } 18 22 19 23 function isTumblrUserURL(url){ … … 32 36 } 33 37 34 function getURLByID(id){ 38 function getURLByID(id, token){ 39 if (token) return "http://www.tumblr.com/reblog/" + id + "/" + token + "?redirect_to=/dashboard"; 35 40 return "http://www.tumblr.com/reblog/" + id; 36 41 } 37 42 38 function getSource(url){ 39 with(D()){ 40 return xhttp.get(url) 41 } 43 // copy from tombloo 44 function unescapeHTML(s){ 45 return s.replace( 46 /&/g, '&').replace( 47 /"/g, '"').replace( 48 /</g, '<').replace( 49 />/g, '>'); 50 } 51 52 // copy from tombloo 53 function 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 } 42 60 } 43 61 … … 80 98 } 81 99 82 function postData(url, aData){83 with(D()){84 return xhttp.post(url, aData)85 }86 }87 88 100 function reblog(aURL){ 89 101 var id = getIDByPermalink(aURL); … … 96 108 } 97 109 } 98 var url = getURLByID(id);99 110 window.Minibuffer.status('ReblogCommand'+id, 'Reblog ...'); 100 getSource(url). 111 d = D(); 112 var url = aURL; 113 d.xhttp.get(url). 101 114 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)))); 103 121 }). 104 122 next(function(){ window.Minibuffer.status('ReblogCommand'+id, 'Reblog ... done.', 100); d.call()}). 105 123 error(function(){ 106 if(confirm('reblog manually ? \n' + url)) reblogManually( aURL);124 if(confirm('reblog manually ? \n' + url)) reblogManually(url); 107 125 d.call(); 108 126 }); … … 162 180 var urls = []; 163 181 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 } 166 189 }else if(stdin.every(function(a){return typeof a == 'string'})){ 167 190 // command line is 'location | reblog'
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)