Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created June 18, 2009 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitode909/131771 to your computer and use it in GitHub Desktop.
Save hitode909/131771 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name simple twitter
// @namespace http://www.hatena.ne.jp/hitode909/
// @description make posts simple.
// @include http://twitter.com/*
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
(function(){
$('li.status').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.verbs = [];
this.verbMode = false;
this.toggleView = function() {
this.verbMode = !this.verbMode;
if (this.verbMode) {
this.content.html( this.replyTo + this.verbs.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.verbs = 'Failed to receive data.';
return;
};
self.verbs = [];
$.each(mecab, function(){
// それっぽいものだけ取り出す
var features = this.feature.split(',');
if (features[0] == '動詞' ||
(features[0] == '名詞' && ['一般', '固有名詞'].indexOf(features[1]) != -1)) {
if (features[6] == '*'){
self.verbs.push(this.surface);
} else {
self.verbs.push(features[6]);
}
}
});
self.verbs = $.unique(self.verbs);
self.toggleView();
}
});
});
})(jQuery);
@Korb
Copy link

Korb commented Jul 27, 2022

What exactly does this script do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment