Hacker News Filter Submissions By Site

hide submissions from from sites you don't like

  1. // ==UserScript==
  2. // @name Hacker News Filter Submissions By Site
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description hide submissions from from sites you don't like
  6. // @author bigguy
  7. // @match https://news.ycombinator.com/news*
  8. // @match https://news.ycombinator.com/news
  9. // @match https://news.ycombinator.com/
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16.  
  17. //quick remove promos
  18. const FIX_NUMBERING = false;
  19.  
  20. [...(document.querySelector('table.itemList')?.rows ?? [])]
  21. .reduce((a, _r, i, rows) => (i % 3 ? a : [...a, rows.slice(i, i + 3)]), [])
  22. .filter((row) => row.length === 3)
  23. .filter(([title]) => !title.querySelector('td.votelinks'))
  24. .forEach((rows) => rows.forEach((row) => row.remove()));
  25.  
  26. if (FIX_NUMBERING) {
  27. document
  28. .querySelectorAll('span.rank')
  29. .forEach?.((s, i) => s.textContent && (s.textContent = `${i + 1}.`));
  30. }
  31.  
  32. var fucks = GM_getValue("fuckers",[]); //local storage within userscript space
  33. console.log("fucker site filter on");
  34. document.getElementsByClassName('pagetop')[1].style="display:none";
  35. var count = 0;
  36. var filtered = 0;
  37. var counter = document.createElement('span');
  38. var subtexts = document.querySelectorAll('.subtext');
  39. var things = document.querySelectorAll('.athing');
  40.  
  41. console.log(subtexts.length);
  42. console.log(things.length)
  43.  
  44. for (let j=0;j<subtexts.length;j++) {
  45. var user = subtexts[j].getElementsByClassName('hnuser')[0];
  46. if (user!=undefined){
  47. user = user.innerText;
  48. } else {
  49. let thinymabob = things[j].getElementsByClassName("storylink")[0];
  50. thinymabob ? thinymabob.classList.add('promo') : null;
  51. }
  52. console.log(user)
  53. }
  54.  
  55. things.forEach(function(post) {
  56. if (post.getElementsByClassName('sitestr').length < 1) return;
  57. var site = post.getElementsByClassName('sitestr')[0].innerText;
  58.  
  59.  
  60.  
  61.  
  62. var a = document.createElement('a');
  63. //a.class = 'togg';
  64. a.href = 'javascript:void(0)';
  65. a.style='cursor:pointer;';
  66. a.innerText = " [Y] ";
  67. count++;
  68.  
  69. //a.onmouseover = function (){a.innerText = " [FILTER] "};
  70. //a.onmouseout = function (){a.innerText = " [Y] "};
  71. a.onclick = function test(){ site = post.getElementsByClassName('sitestr')[0].innerText; this.innerText = "[FUCKER]"; fucks.indexOf(site) === -1 ? fucks.push(site) : null; GM_setValue("fuckers", fucks); console.log(fucks); post.getElementsByClassName("title")[1].innerText = "'" + site + "' filtered from now on";} //fucks.join("','")
  72. post.getElementsByClassName('comhead')[0].prepend(a);
  73. var titleHolder = post.getElementsByClassName("storylink")[0] || null;
  74. var oldTitle = titleHolder ? titleHolder.innerText : "";
  75. //console.log(titleHolder.classList);
  76.  
  77. if (fucks.includes(site) || (titleHolder && titleHolder.classList && titleHolder.classList.contains("promo"))){
  78. console.log(site + ' the fucker, has been blocked');
  79. var derTitle = post.getElementsByClassName("title")[1];
  80. var oldDerTitle = derTitle.innerText;
  81. console.log(derTitle.innerText)
  82. filtered++;
  83.  
  84.  
  85. var g = post.getElementsByClassName("votearrow");
  86.  
  87. a.innerText = " . ";
  88. a.onmouseout = function (){a.innerText = " . "};
  89. a.className = 'subtext';
  90.  
  91. if ((titleHolder && titleHolder.classList && titleHolder.classList.contains("promo")) || g.length==0){
  92.  
  93. a.onmouseover = function (){a.innerText = oldTitle};
  94. derTitle.innerHTML = "<span class='push subtext'>[HN-PROMO FILTERED]<\span>";
  95. }
  96. else {
  97. console.log(titleHolder);
  98. a.onmouseover = function (){a.innerText = " [UNFILTER] "};
  99. if ( g ) {
  100. g[0].title = derTitle.innerText
  101. }
  102. derTitle.innerHTML = "<span class='push subtext'>["+site.toUpperCase() +" FILTERED]<\span>";
  103. }
  104.  
  105. var b = a.cloneNode();
  106. b.innerText = " . "; //[P]
  107. //b.onmouseover = function (){b.innerText = oldTitle};
  108. //post.getElementsByClassName("push")[0].onmouseover = function (){post.getElementsByClassName("push")[0].innerText = oldTitle};
  109. //post.getElementsByClassName("push")[0].onmouseout = function (){post.getElementsByClassName("push")[0].innerText = "["+site.toUpperCase() +" FILTERED]"};
  110. b.onmouseover = function (){b.innerText = " [Preview] "};
  111. b.onmouseout = function (){b.innerText = " . "};
  112. b.alt='preview';
  113. b.onclick = function (){post.getElementsByClassName("title")[1].innerText = oldDerTitle};
  114. a.onmouseover = function (){a.innerText=" [UNDO] "};
  115. a.onclick = function test(){ fucks.indexOf(site) >= 0 ? delete fucks[fucks.indexOf(site)] : null;console.log("site index? ",fucks.indexOf(site)); GM_setValue("fuckers", fucks); console.log(fucks);} //fucks.join("','")
  116. post.getElementsByClassName('title')[1].append(b);
  117. var c = post.getElementsByClassName('title')[1]
  118. if (c) {
  119. c.prepend(a);
  120. }
  121. }
  122. });
  123. counter.innerText=filtered+"/"+count+" submissions filtered!";
  124. document.getElementsByClassName('pagetop')[0].append(counter);
  125. })();