-
-
Save azu/807644 to your computer and use it in GitHub Desktop.
Togetterをフィルタリング、GUIで設定可能
This file contains hidden or 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/* | |
// @require https://github.com/azu/usconfig/raw/v1.13/usconfig.js | |
// ==/UserScript== | |
// 設定画面の定義 - http://d.hatena.ne.jp/h1mesuke/20100713/p1 | |
Config.define('usc_basic', function() { | |
with (this.builder) { | |
var blacklist = ['carejinzaibank', 'ptotjinzaibank', 'nursejinzaibank']; | |
dialog( | |
"TogetterFilter Settings", | |
{ width: 500, height: 500 }, | |
section( | |
"Black list ID", | |
"各行にフィルタリングしたいIDを書く", | |
grid( | |
textarea("Black List:", 'blacklist', blacklist.join("\n"), | |
{ label: 'top', | |
cols : 30, | |
rows : 20}) | |
)) | |
) | |
} | |
}, { | |
saveKey: 'GM_config' | |
}); | |
GM_registerMenuCommand('TogetterFilter Setting', Config.open); | |
// 設定のロード | |
var settings = Config.load(); | |
var blackListArray = qw(settings.blacklist); | |
var blackList = new RegExp('^(?:' + 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) { | |
var selector, items, i, len, thisLink; | |
if (/^http:\/\/togetter\.com\/li\/\d+/.test(location.href)) { | |
selector = 'div.list_body > div.status > a[href^="http://twitter.com"], div.status > a.twttrname'; | |
} else { | |
selector = 'div.info_infomation > a.icon_author'; | |
} | |
items = node.querySelectorAll(selector); | |
for (i = 0,len = items.length; i < len; ++i) { | |
thisLink = items[i]; | |
// ループでtestを使うと、lastIndexが継続しっぱなしでおかしくなる | |
// http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/#regular-expression-literal-and-regexp-objects | |
if (!!~thisLink.text.search(blackList)) { | |
thisLink.parentNode.parentNode.parentNode.parentNode.style.opacity = 0.1; | |
} | |
} | |
} | |
// 文字列から空改行をなくした配列を返す | |
function qw(words) { | |
var a = String(words).split("\n"); | |
if (a.length > 0 && a[0] == "") | |
a.unshift(); | |
if (a[a.length - 1] == "") | |
a.pop(); | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
猿アイコンのユーザーコマンドから設定画面を開いてIDを追加できる