Skip to content

Instantly share code, notes, and snippets.

@otsune
Forked from mEGGrim/togetterfilter.user.js
Created February 2, 2011 06:13
Show Gist options
  • Save otsune/807319 to your computer and use it in GitHub Desktop.
Save otsune/807319 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TogetterFilter
// @namespace TogetterFilter
// @description Togetterを任意のユーザー名を用いてフィルタリング
// @include http://togetter.com/*
// @require https://gist.github.com/434406.txt
// ==/UserScript==
// Based on http://d.hatena.ne.jp/mEGGrim/20101019/1287684499
// ここにフィルタリングしたいユーザーのIDを''で囲い、,で区切って記述して下さい
var blackListArray = ['carejinzaibank', 'ptotjinzaibank', 'nursejinzaibank'];
const DATABASE_URL = 'http://wedata.net/databases/TogetterFilter/items.json';
var database = new Wedata.Database(DATABASE_URL);
database.get(function(items) {
items.forEach(function(item) {
var id = item.data.id.match(/([a-z1-9_]{1,14}(?![a-z0-9_]))/i);
if (id){
blackListArray.push(id);
}
});
});
GM_registerMenuCommand('TogetterFilter - clear cache', function() {
database.clearCache();
});
var blackList = new RegExp('^(?:' + unique(blackListArray).join('|') + ')$', 'g');
// AutoPagerizeで増えた分ではない、1ページ目のフィルタリング
filter(document);
// AutoPagerizeにfilterをイベントとして追加
// 要AutoPagerize(version 0.40 以降)、jAutoPagerize(Rev: 33889+ 以降)
// 参考URL: http://d.hatena.ne.jp/os0x/20090829/1251556449
document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
var node = evt.target;
filter(node);
}, false);
function filter(node) {
if(document.URL.match(/^http:\/\/togetter\.com\/li\/\d+/)) {
filterTweets(node);
} else {
filterLists(node);
}
}
function filterTweets(node) {
//各まとめページの発言をフィルタリング
var items = document.querySelectorAll(
'div.list_body > div.status > a[href^="http://twitter.com"]'
);
for (var i = 0; i < items.length; i++) {
var thisLink = items[i];
if(thisLink.innerHTML.match(blackList)) {
gone(thisLink);
}
}
// コメント欄をフィルタリング
var items = document.querySelectorAll(
'div.status > a.twttrname'
);
for (var i = 0; i < items.length; i++) {
var thisLink = items[i];
if(thisLink.innerHTML.match(blackList)) {
gone(thisLink);
}
}
}
function filterLists(node) {
var items = document.querySelectorAll(
'div.info_infomation > a.icon_author'
);
for (var i = 0; i < items.length; i++) {
var thisLink = items[i];
if(thisLink.innerHTML.match(blackList)) {
gone(thisLink);
}
}
}
function gone(item){
//display = 'none'にしてフィルタリング
// item.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
item.parentNode.parentNode.parentNode.parentNode.style.opacity = 0.1;
}
function unique(array) {
var storage = {};
var uniqueArray = [];
var i, value;
for ( i=0; i<array.length; i++) {
value = array[i];
if (!(value in storage)) {
storage[value] = true;
uniqueArray.push(value);
}
}
return uniqueArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment