Last active
March 23, 2018 07:27
-
-
Save khsk/3ba7b2f2148f8d757d26b49ded5ae082 to your computer and use it in GitHub Desktop.
新 Qiitaのフィードから特定ユーザーの投稿を非表示にするユーザースクリプト ref: https://qiita.com/khsk/items/4817baf510812893acf5
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 Qiita user filter for feed | |
// @namespace khsk | |
// @description フィードから特定ユーザーの投稿を非表示にする | |
// @include https://qiita.com/ | |
// @include https://qiita.com/trend | |
// @include https://qiita.com/timeline | |
// @include https://qiita.com/tag-feed | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
console.time('userfilter'); | |
const NG_USERS = [ | |
]; | |
const filtering = () => { | |
// トレンド, ユーザーランキング, タイムライン アイコンリンク, タグフィード アイコンリンク(こっちはユーザー名リンクでもよかった), おすすめユーザー(多分出ないけど) | |
const targets = document.querySelectorAll('a.tr-Item_author, div.ra-User_screenname>a, a.tl-ItemContent_userImage, a.tf-ItemContent_userImage, a.tl-RecommendedUser_screenname') | |
Array.prototype.forEach.call(targets,function(target){ | |
user = target.href.match(/https?:\/\/qiita.com\/([^/]+)/)[1]; | |
if (NG_USERS.indexOf(user) != -1) { | |
switch (target.className) { | |
case 'tr-Item_author': | |
case 'tl-RecommendedUser_screenname': | |
target.parentNode.parentNode.parentNode.parentNode.style.display = 'none'; | |
break; | |
case '': | |
target.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = 'none'; | |
break; | |
case 'tl-ItemContent_userImage': | |
case 'tf-ItemContent_userImage': | |
target.parentNode.parentNode.parentNode.style.display = 'none'; | |
break; | |
default: | |
console.log(target); | |
break | |
} | |
} | |
}); | |
} | |
// 変更を監視する。追加分だけには対応しておらず、毎回全チェック。 | |
var mo = new MutationObserver(function(data1, data2) { | |
filtering(); | |
}); | |
// 監視対象が大きいが妥協 | |
const root = document.querySelector('div') | |
const options = {childList: true, subtree:true}; | |
mo.observe(root, options); | |
filtering(); | |
console.timeEnd('userfilter'); | |
// todo コメント非表示 需要が生まれたら |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment