// ==UserScript== // @name nonsensial twitter // @namespace http://www.hatena.ne.jp/tily/ // @description make posts nonsense. // @include http://twitter.com/* // @require http://code.jquery.com/jquery-latest.js // ==/UserScript== (function(){ $('li.status:lt(40)').each(function(){ // originalContentは初期状態のHTML this.content = $('span.entry-content', $(this)); this.originalContent = this.content.html(); // contentからreply,anchor切り出す // textは形態素解析の本文になる部分 var replyExp = /@\\w+\<\/a\>\s?/g; this.replyTo = (this.originalContent.match(replyExp) || []).join(' '); this.content.html(this.content.html().replace(replyExp,'')); this.anchors = $('a',this.content).remove(); this.text = this.content.text(); this.words = []; this.verbMode = false; this.toggleView = function() { this.verbMode = !this.verbMode; if (this.verbMode) { this.content.html( this.replyTo + this.words.join('') ).append(this.anchors); } else { this.content.html(this.originalContent); } }; $(this).click(this.toggleView); this.content.empty().append($(document.createElement('img')).attr('src', 'http://static.twitter.com/images/ajax.gif')); // JSON取得 var self = this; GM_xmlhttpRequest({ method: "GET", url: 'http://mimitako.net/api/mecapi.cgi?'+$.param({sentence:this.text, format:'json', response:'surface,feature'}), onload: function(response) { var mecab; try { mecab = eval(response.responseText); } catch(e) { self.words = 'Failed to receive data.'; return; }; self.words = []; $.each(mecab, function(){ // それっぽいものだけ取り出す var features = this.feature.split(','); if (features[0] != '動詞' && features[0] != '名詞' && features[0] != '形容詞') { self.words.push(features[6]); } }); self.toggleView(); } }); }); })(jQuery);