Skip to content

Instantly share code, notes, and snippets.

@mmmpa
Last active May 9, 2019 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmpa/355edc5b5df75ea8fdcb66b40d1c8578 to your computer and use it in GitHub Desktop.
Save mmmpa/355edc5b5df75ea8fdcb66b40d1c8578 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name remove container
// @include http*://b.hatena.ne.jp*
// ==/UserScript==
(function () {
const configure = {
'https://anond.hatelabo.jp': true,
'https://togetter.com': true,
'https://twitter.com': true,
'https://kyoko-np.net': true,
'http://blog.livedoor.jp': {
users: new Set(['dqnplus', 'itsoku']),
},
'https://qiita.com': {
users: new Set(['poly_soft', 'Yametaro']),
words: ['ワイ', 'パパ', '消耗', '歳'],
},
};
const list = new Set(Object.keys(configure));
const reg = /^(https?:\/\/[^/]*)\/?([^/]*)/;
function isRemovable (a) {
a.getAttribute('href').match(reg);
const {
'$1': domain,
'$2': user,
} = RegExp;
const detail = list.has(domain) && configure[domain];
const content = a.innerHTML;
if (detail === false) { return false; }
if (detail === true) { return true; }
if (detail.users && detail.users.has(user)) { return true; }
if (detail.words && detail.words.some(s => content.includes(s))) { return true; }
return false;
}
function removeContainer (now) {
while ((now = now.parentNode) && now.tagName !== 'LI') {}
now && now.parentNode && now.parentNode.removeChild(now);
}
Array.from(document.querySelectorAll('h3 a'))
.filter(isRemovable)
.forEach(removeContainer);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment