Skip to content

Instantly share code, notes, and snippets.

@azu
Created March 17, 2009 06:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save azu/80364 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Twitter Change Style
// @namespace http://tyoro.orz.ne.jp/
// @include http://twitter.com/
// @include http://twitter.com/*/with_friends*
// @include https://twitter.com/
// @include https://twitter.com/*/with_friends*
// @version 1.3.0
// ==/UserScript==
// original script : http://userscripts.org/scripts/show/10638
// by http://twitter.com/youpy
// original script : http://twitter.g.hatena.ne.jp/trickstar_os/20070716/1184579609
// by os9(trickstar_os) ( http://d.hatena.ne.jp/trickstar_os/ )
// author: tyoro ( http://tyoro.orz.ne.jp/exe/ )
(function(){
//////////////////ユーザー定義
//サンプルデータでは背景色と非表示化くらいしか設定してませんが、文字の色やサイズ変更とかも出来ます。
//自身の名前が含まれる発言のスタイル(色を指定
var in_color = "background-color:#CCCCFF;";
//自分の発言のスタイル
var my_color = "background-color:#CCFFCC;";
//送信者一致
var from_array = [
// {'name':'kyoujin', 'style':'background-color:#ffffcc;'},
// {'name':'otsune', 'style':'background-color:#ffffcc;'},
];
//宛先一致
var to_array = [
// {'name':'reblog', 'style':'background-color:#ffaaff;'},
];
//本文一致
var text_array = [
// {'name':'++', 'style':'background-color:#444444;'},
// {'name':'.*', 'regexp':true, 'style':'background-color:#445544;'},
// {'name':'おはよう', 'style':'background-color:#ffcccc;'},
// {'name':'ちょろだよー', 'style':'display:none;'},
];
// 正規表現にすると、エスケープが必要になるのが微妙なところ
/////////////////以下プログラムソース(触らない方がよさげ
window.jQuery = unsafeWindow.jQuery;
var reg_user;
function mainloop(node){
node = node || document;
var updates = jQuery('.hentry', node);
if(updates.length){
jQuery.map(updates, colorchange );
}
}
function colorchange(e) {
if(e.added){return;}
var content = jQuery('.entry-content',e).text();
if(content) {
if(content.match(reg_user)){
e.style.cssText = in_color;
}
foreach(text_array, function(_text){
if (!_text) return;
var reg_text = !!_text.regexp ? new RegExp(_text.name, 'i') : _text.name;
if (content.match(reg_text))
e.style.cssText = _text.style;
});
}
var from = jQuery('.status-body strong>a',e).text();
if(from) {
foreach(from_array, function(_from){
if (!_from) return;
if(_from.name == from)
e.style.cssText = _from.style;
});
}
var meta_text = jQuery('.entry-meta>a:contains("in reply to")',e).text();
if(meta_text){
var to_text = meta_text.replace(/[\s\w]* /,'');
if(to_text != null) {
foreach(to_array, function(_to){
if (!_to) return;
if(_to.name == to_text )
e.style.cssText = _to.style;
});
}
}
e.added = true;
}
function cs_init(){
var username = jQuery.trim(jQuery("#me_name").text());
if(!username) {return false;} //userの取得に失敗
reg_user = new RegExp('[\\W]' + username + '[\\W]'); // 正規表現で英数字と_以外に連続したユーザー名にマッチさせる
from_array.push( { 'name':username,'style':my_color } );
return true;
}
//メインループの呼び出し
if(!cs_init()) return;
mainloop();
addFilter(mainloop);
// addRefreshFilter(function(){setTimeout(mainloop, 0)});
function foreach(arr,callback) {
for (var i = 0, l = arr.length;i < l; i++) callback(arr[i], i, arr);
};
function addFilter(filter, i) {
i = i || 4;
if (window.AutoPagerize) {
window.AutoPagerize.addFilter(function(){mainloop()});
} else if (i > 1) {
var f = arguments.callee;
setTimeout(function() {
f(filter, i - 1);
}, 1000);
}
}
/*
function addRefreshFilter(filter, i) {
i = i || 4;
if (window.AutoRefresh && window.AutoRefresh.addFilter) {
window.AutoRefresh.addFilter(filter);
} else if (i > 1) {
var f = arguments.callee;
setTimeout(function() {
f(filter, i - 1);
}, 1000);
}
}
*/
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment