Advertisement
Guest User

Untitled

a guest
May 8th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        stackexchange
  3. // @namespace   stackexchange
  4. // @include     http://stackexchange.com/questions?pagesize=50*
  5. // @version     1
  6. // @description Small script to block questions from being shown in the stackexchange hot topics list
  7. // ==/UserScript==
  8.  
  9.  
  10. //reads blocklist from storage
  11. var listval = GM_getValue("blocklist");
  12. var blocklist = [];
  13. if(listval)
  14. {
  15.     blocklist = blocklist.concat(JSON.parse(listval));
  16. }
  17.  
  18. //make list available in website scope
  19. unsafeWindow.blocklist = blocklist;
  20.  
  21. //open header links in new tab/window
  22. [].forEach.call(
  23.     document.querySelectorAll('div.question-hot h2 a'),
  24.     function(el) {
  25.         el.setAttribute('target', '_blank');
  26.     }
  27. );
  28.  
  29. //change imagelink click handling
  30. [].forEach.call(
  31.     document.querySelectorAll('div.hot-question-site-icon a img'),
  32.     function(el) {
  33.         var a = el.parentNode;
  34.         var questionUrl = a.href.match(/http:\/\/[^/]*\/questions\/[0-9]*\//)[0];
  35.         if(blocklist.indexOf(questionUrl) >= 0) {
  36.             //hide
  37.             a.parentNode.parentNode.style.display='none';
  38.         } else {
  39.             //set listener
  40.             a.addEventListener('click', xLinkHandler, false);
  41.             a.title = 'ignore this thread';
  42.             a.href = questionUrl;
  43.         }
  44.     }
  45. );
  46.  
  47. //click on an image link hides whole div and adds Url to blocklist
  48. function xLinkHandler(blockEvent) {
  49.     blockEvent.preventDefault();
  50.     blockEvent.target.parentNode.parentNode.parentNode.style.display='none';
  51.     var questionUrl = blockEvent.target.parentNode.href;
  52.     blocklist = blocklist.concat(questionUrl);
  53.     GM_setValue("blocklist", JSON.stringify(blocklist));
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement