Skip to content

Instantly share code, notes, and snippets.

@tily
Forked from hitode909/simple_twitter.user.js
Created June 22, 2009 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tily/133987 to your computer and use it in GitHub Desktop.
Save tily/133987 to your computer and use it in GitHub Desktop.
make twitter statuses nonsense
// ==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 = /@\<a href=\"\/\w+\"\>\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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment