Changeset 22421

Show
Ignore:
Timestamp:
10/31/08 14:45:15 (5 years ago)
Author:
miru
Message:
 
Files:
1 modified

Legend:

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

    r8688 r22421  
    2222(function(){ 
    2323 
     24 
     25var hatenauserid = 'mirupreza'; 
     26var postdomain = 'http://d.hatena.ne.jp'; 
     27 
    2428var $X = window.Minibuffer.$X 
    2529var D = window.Minibuffer.D 
     
    3034 
    3135function 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; 
    3338} 
    3439 
     
    6772        }); 
    6873        // 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)); 
    7075        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, ''); 
    7280 
    7381        return { 
    7482                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 
    7986        }; 
    8087} 
     
    160167                                d.fail("notloggedin"); 
    161168                        } 
    162                         var username = result[0].nodeValue; 
     169                        var username = hatenauserid; 
    163170                        return username; 
    164171                } ).next( function (username) { 
    165172                        return xhttp.get( [ 
    166                                 'http://d.hatena.ne.jp', 
     173                                postdomain, 
    167174                                username, 
    168175                                'edit' 
     
    173180                        var htmlForm = new HTMLForm(doc, res.finalUrl); 
    174181                        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' + 
    176201                                body.map( function (stat) { 
    177202                                        return [ 
    178203                                                '', 
    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>', 
    180205                                                stat.tweet.replace(/\|/g, '&#124;'), 
    181                                                 '[' + stat.permalink + ':title=' + stat.ago + ']', 
     206                                                '<a href="' + stat.permalink + '">link</a>', 
    182207                                                '' 
    183208                                        ].join( '|'); 
    184                                 } ).join("\n") + '\n\n\n' + f.body.value; 
     209                                } ).join("\n")  + '\n\n\n' + f.body.value; 
    185210                        return f.click('edit'); 
    186211 
     
    201226          var args = this.args; 
    202227          var urls = []; 
     228 
     229// tag init 
     230          tagArray = new Array(""); 
     231          tagArray.length = 0; 
     232 
    203233          if(!stdin.length){ 
    204234                  // command line is just 'share-twitter-on-hatenaDiary' 
     
    208238                  urls = stdin.map(function(node){return node.href}); 
    209239          }else{ 
    210                   status('ShareTwitterOnTumblr'+time, 'command line error!', 1000); 
     240                  status('ShareTwitterOnHatenaDiary'+time, 'command line error!', 1000); 
    211241                  return stdin; 
    212242          } 
    213243          var time = new Date().getTime(); 
    214244          if(!urls.every(isTwitterStatusURL)){ 
    215                   status('ShareTwitterOnTumblr'+time, 'There is invalid URL', 1000); 
     245                  status('ShareTwitterOnHatenaDiary'+time, 'There is invalid URL', 1000); 
    216246                  return stdin; 
    217247          } 
     
    221251          }) 
    222252          with(D()){ 
    223                   status('ShareTwitterOnTumblr'+time, 'Share ...'); 
     253                  status('ShareTwitterOnHatenaDiary'+time, 'Share ...'); 
    224254                  parallel(urls.map(function(aURL){ 
    225255                          return getSource(aURL). 
     
    232262                        }). 
    233263                        next(function(arg){ 
    234                                 status('ShareTwitterOnTumblr'+time, 'Share ... done', 100); 
     264                                status('ShareTwitterOnHatenaDiary'+time, 'Share ... done', 100); 
    235265                        }) 
    236266          }