Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name stackexchange
- // @namespace stackexchange
- // @include http://stackexchange.com/questions?pagesize=50*
- // @version 1
- // @description Small script to block questions from being shown in the stackexchange hot topics list
- // ==/UserScript==
- //reads blocklist from storage
- var listval = GM_getValue("blocklist");
- var blocklist = [];
- if(listval)
- {
- blocklist = blocklist.concat(JSON.parse(listval));
- }
- //make list available in website scope
- unsafeWindow.blocklist = blocklist;
- //open header links in new tab/window
- [].forEach.call(
- document.querySelectorAll('div.question-hot h2 a'),
- function(el) {
- el.setAttribute('target', '_blank');
- }
- );
- //change imagelink click handling
- [].forEach.call(
- document.querySelectorAll('div.hot-question-site-icon a img'),
- function(el) {
- var a = el.parentNode;
- var questionUrl = a.href.match(/http:\/\/[^/]*\/questions\/[0-9]*\//)[0];
- if(blocklist.indexOf(questionUrl) >= 0) {
- //hide
- a.parentNode.parentNode.style.display='none';
- } else {
- //set listener
- a.addEventListener('click', xLinkHandler, false);
- a.title = 'ignore this thread';
- a.href = questionUrl;
- }
- }
- );
- //click on an image link hides whole div and adds Url to blocklist
- function xLinkHandler(blockEvent) {
- blockEvent.preventDefault();
- blockEvent.target.parentNode.parentNode.parentNode.style.display='none';
- var questionUrl = blockEvent.target.parentNode.href;
- blocklist = blocklist.concat(questionUrl);
- GM_setValue("blocklist", JSON.stringify(blocklist));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement