TogetterFilter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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'); | |
// AutoPagerizeで増えた分ではない、1ページ目のフィルタリング | |
filterTweets(); | |
filterLists(); | |
// 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; | |
var requestURL = evt.newValue; | |
var parentNode = evt.relatedNode; | |
if(document.URL.match(/http:\/\/togetter.com\/li\/*/)) | |
{ | |
filterTweets(); | |
} | |
else | |
{ | |
filterLists(); | |
} | |
}, false); | |
})(); | |
function filterTweets() | |
{ | |
//各まとめページの発言をフィルタリング | |
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'; | |
} | |
} | |
} | |
function filterLists() | |
{ | |
column = document.evaluate( | |
//*のtwitterまとめ, でまとめ主のIDを検索してフィルタリング | |
"/html/body/div/div[3]/div/div/div/ul/li/div/div[2]/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'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment