Created
December 10, 2014 19:24
-
-
Save tranch/9550b2f51b1b128283b7 to your computer and use it in GitHub Desktop.
Hacker News Spam Blocker
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 block it | |
| // @namespace tranch | |
| // @description block item by domain on hacknews | |
| // @include http://news.dbanotes.net/* | |
| // @version 0.1 | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| var DB_NAME = 'HackerNewBlackList'; | |
| var items = document.querySelectorAll('td.title a'), item; | |
| var black_list = JSON.parse(localStorage.getItem(DB_NAME)) || []; | |
| var block_button; | |
| window.tch_block_item = function (item_id) { | |
| item = document.querySelector('#' + item_id); | |
| var domain = item.href.split('/')[2]; | |
| var json = localStorage.getItem('HackerNewBlackList') || '[]'; | |
| var black_list = JSON.parse(json); | |
| black_list.push(domain); | |
| localStorage.setItem('HackerNewBlackList', JSON.stringify(black_list)); | |
| tch_hide_item(item); | |
| }; | |
| window.tch_hide_item = function (node) { | |
| node.parentNode.parentNode.nextSibling.nextSibling.style.display = 'none'; | |
| node.parentNode.parentNode.nextSibling.style.display = 'none'; | |
| node.parentNode.parentNode.style.display = 'none'; | |
| }; | |
| for (var i=0; i<items.length; i++) { | |
| item = items[i]; | |
| item.id = 'tread_' + i; | |
| block_button = document.createElement('a'); | |
| block_button.href = 'javascript:tch_block_item("'+item.id+'")'; | |
| block_button.innerHTML = 'block'; | |
| option_container = item.parentNode.parentNode.nextSibling.firstChild.nextSibling; | |
| option_container.innerHTML += ' | '; | |
| option_container.appendChild(block_button); | |
| for (var ib=0; ib<black_list.length; ib++) { | |
| if (item.href.contains(black_list[ib])) { | |
| tch_hide_item(item); | |
| } | |
| } | |
| } | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment