Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2010 03:06
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 anonymous/633537 to your computer and use it in GitHub Desktop.
Save anonymous/633537 to your computer and use it in GitHub Desktop.
TogetterFilter.js
// ==UserScript==
// @name TogetterFilter
// @namespace TogetterFilter
// @description Togetterを任意のユーザー名を用いてフィルタリング
// @include http://togetter.com/*
// ==/UserScript==
(function() {
// ここにフィルタリングしたいユーザーのIDを''で囲い、,で区切って記述して下さい
blackListArray = ['username1', 'username2', 'username3'];
blackListStr = '^(' + blackListArray[0];
delete blackListArray[0];
for(blackListElement in blackListArray)
{
blackListStr += "|" + blackListArray[blackListElement];
}
blackListStr += ')$';
blackList = new RegExp(blackListStr, 'g');
var FilterContainer = function() {
this.__container = {};
this.addFilter = function(name,func) {
this.__container[name] = func;
return this;
}
this.batch = function(nodes) {
for each (var node in nodes)
for each (var filter in this.__container) filter(node);
}
};
if(window.Filterize == undefined)
window.Filterize = {
onAutoPagerized : new FilterContainer(),
onLoaded : new FilterContainer(),
};
// for AutoPagerize
if(window.AutoPagerize != undefined)
window.AutoPagerize.addFilter(function (context){
return Filterize.onAutoPagerized.batch.call(Filterize.onAutoPagerized, context);
});
// for loaded
window.Filterize.timer = setTimeout(function() {
for each(var filter in window.Filterize)
if(filter.batch) filter.batch([document]);
clearTimeout(window.Filterize.timer);
},0);
if(window.Filterize != undefined)
Filterize.onAutoPagerized.addFilter('applyWordBreak', function (context){
if(document.URL.match(/http:\/\/togetter.com\/li\/*/))
{
//各まとめページの発言をフィルタリング
column = document.evaluate(
"/html/body/div/div[3]/div/div/div[3]/ul/li/div/div[2]/div[2]/a",
document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (var i = 0; i < column.snapshotLength; i++) {
thisLink = column.snapshotItem(i);
if(thisLink.innerHTML.match(blackList))
{
//display = 'none'にしてフィルタリング
thisLink.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
}
}
// コメント欄をフィルタリング
column = document.evaluate(
"/html/body/div/div/div/div/div/ul/li/div/div/div/div/a",
document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (var i = 0; i < column.snapshotLength; i++) {
thisLink = column.snapshotItem(i);
if(thisLink.innerHTML.match(blackList))
{
//display = 'none'にしてフィルタリング
thisLink.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
}
}
}
else
{
column = document.evaluate(
//*のtwitterまとめ, でまとめ主のIDを検索してフィルタリング
"/html/body/div/div[3]/div/div/div/ul/li/div/div[2]/div[3]/a",
document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (var i = 0; i < column.snapshotLength; i++) {
thisLink = column.snapshotItem(i);
if(thisLink.innerHTML.match(blackList))
{
//display = 'none'にしてフィルタリング
thisLink.parentNode.parentNode.parentNode.parentNode.style.display = 'none';
}
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment