Changeset 22421
- Timestamp:
- 10/31/08 14:45:15 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/sharetwitteronhatenadiary.user.js
r8688 r22421 22 22 (function(){ 23 23 24 25 var hatenauserid = 'mirupreza'; 26 var postdomain = 'http://d.hatena.ne.jp'; 27 24 28 var $X = window.Minibuffer.$X 25 29 var D = window.Minibuffer.D … … 30 34 31 35 function isTwitterStatusURL(aURL){ 32 return aURL.match("^https?://twitter\\.com/[^/]+/statuses/\\d+") ? true : false; 36 //return aURL.match("^https?://twitter\\.com/[^/]+/statuses/\\d+") ? true : false; 37 return aURL.match("^https?://twitter\\.com/[^/]+/status/\\d+") ? true : false; 33 38 } 34 39 … … 67 72 }); 68 73 // scrape status 69 var body = normalizeText($X(' id("permalink")/div/p[1]//text()', doc));74 var body = normalizeText($X('//div[@class="desc-inner"]/p[1]//text()', doc)); 70 75 var name = aURL.match('https?://twitter\\.com/([^/]+)')[1]; 71 var ago = $X('id("permalink")//span[@class="meta"]/text()[1]', doc, String); 76 var nick = normalizeText($X('//div[@class="full-name"]/text()', doc)); 77 78 tagArray.push("["+name+"]"); 79 body = body.replace(/\[.*\]/g, ''); 72 80 73 81 return { 74 82 name: name, 75 tweet: body, 76 permalink: aURL, 77 // FIXME: normalizeText() something wrong for this script. 78 ago: ago[0].nodeValue.replace(/^\s+|\s+$|from/g, '').replace(/\s+/g, ' ') 83 nick: nick, 84 tweet: body, 85 permalink: aURL 79 86 }; 80 87 } … … 160 167 d.fail("notloggedin"); 161 168 } 162 var username = result[0].nodeValue;169 var username = hatenauserid; 163 170 return username; 164 171 } ).next( function (username) { 165 172 return xhttp.get( [ 166 'http://d.hatena.ne.jp',173 postdomain, 167 174 username, 168 175 'edit' … … 173 180 var htmlForm = new HTMLForm(doc, res.finalUrl); 174 181 var f = htmlForm.edit; 175 f.body.value = '*[chat]twitter log\n' + 182 183 // prompt 184 var stringTitle = prompt("Input post title"); 185 if (stringTitle == null) { stringTitle = 'twit log' } 186 187 // Tag string 188 tagArray.sort(); 189 tagArrayUniq = new Array('[twit]'); 190 var oldTag = ''; 191 192 for( var j=0; j<tagArray.length; j++) { 193 if( tagArray[j] != oldTag ) { 194 tagArrayUniq.push( tagArray[j] ); 195 oldTag = tagArray[j]; 196 } 197 } 198 var strTag = tagArrayUniq.join(''); 199 200 f.body.value = '*' + strTag + stringTitle +'\n' + 176 201 body.map( function (stat) { 177 202 return [ 178 203 '', 179 ' [http://twitter.com/' + stat.name + ':title=' + stat.name + ']',204 '<a href="http://twitter.com/' + stat.name + '"><img src="http://img.twitty.jp/twitter/user/' + stat.name + '/m.gif" hight=32 width=32></a>|' + '<a href="http://twitter.com/' + stat.name + '">' + stat.nick + '<br>' + stat.name + '</a>', 180 205 stat.tweet.replace(/\|/g, '|'), 181 ' [' + stat.permalink + ':title=' + stat.ago + ']',206 '<a href="' + stat.permalink + '">link</a>', 182 207 '' 183 208 ].join( '|'); 184 } ).join("\n") + '\n\n\n' + f.body.value;209 } ).join("\n") + '\n\n\n' + f.body.value; 185 210 return f.click('edit'); 186 211 … … 201 226 var args = this.args; 202 227 var urls = []; 228 229 // tag init 230 tagArray = new Array(""); 231 tagArray.length = 0; 232 203 233 if(!stdin.length){ 204 234 // command line is just 'share-twitter-on-hatenaDiary' … … 208 238 urls = stdin.map(function(node){return node.href}); 209 239 }else{ 210 status('ShareTwitterOn Tumblr'+time, 'command line error!', 1000);240 status('ShareTwitterOnHatenaDiary'+time, 'command line error!', 1000); 211 241 return stdin; 212 242 } 213 243 var time = new Date().getTime(); 214 244 if(!urls.every(isTwitterStatusURL)){ 215 status('ShareTwitterOn Tumblr'+time, 'There is invalid URL', 1000);245 status('ShareTwitterOnHatenaDiary'+time, 'There is invalid URL', 1000); 216 246 return stdin; 217 247 } … … 221 251 }) 222 252 with(D()){ 223 status('ShareTwitterOn Tumblr'+time, 'Share ...');253 status('ShareTwitterOnHatenaDiary'+time, 'Share ...'); 224 254 parallel(urls.map(function(aURL){ 225 255 return getSource(aURL). … … 232 262 }). 233 263 next(function(arg){ 234 status('ShareTwitterOn Tumblr'+time, 'Share ... done', 100);264 status('ShareTwitterOnHatenaDiary'+time, 'Share ... done', 100); 235 265 }) 236 266 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)