Advertisement
erinx

4chan cap helper

Apr 10th, 2022
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @id             arch.413chan.net-580a3d1c-2425-453d-9c9f-1b9f1d6c0630@scriptish
  3. // @name           4chan cap helper
  4. // @version        4.03
  5. var version = 4.03;
  6. // anybody with half a brain will tell you that duplicated variables like this is bad. Tough shit.
  7. // @namespace      
  8. // @author         subby
  9. // @description    hides posts that are not selected with the tickbox, for capping
  10. // @include        *://boards.4chan.org/*/thread/*
  11. // @grant          none
  12. // @run-at         document-end
  13. // ==/UserScript==
  14. var despoilcount = 0;
  15. function contains(a, obj) {
  16.     for (var i = 0; i < a.length; i++) {
  17.         if (a[i] === obj) {
  18.             return true;
  19.         }
  20.     }
  21.     return false;
  22. }
  23. function showPosts() {
  24.     //unhide all posts
  25.     var posts = [].slice.call(document.getElementsByClassName("replyContainer"));
  26.     var op = [].slice.call(document.getElementsByClassName("opContainer"));
  27.     for (var i = 0; i < posts.length; i++) {
  28.        posts[i].hidden = false;
  29.     }
  30.     //we do both because one works in 4chanx and one works without.
  31.     op[0].style.display = '';
  32.     op[0].hidden = false;
  33.     startbutton.setAttribute('value', 'Hide unchecked posts'); // What the enduser sees on button
  34.     startbutton.onclick = function() {
  35.         hidePosts();
  36.         onClick();
  37.     };
  38. }
  39. function hidePosts() {
  40.     //get checkboxes
  41.     //get the postcontainers
  42.     //hide the post containers if their id isn't in a checked checkbox
  43.     var postInfos = [].slice.call(document.getElementsByClassName("postInfo"));
  44.     var savenums = ["pc1"];
  45.     var posts = [].slice.call(document.getElementsByClassName("replyContainer"));
  46.     var op = [].slice.call(document.getElementsByClassName("opContainer"));
  47.     for (var i = 0; i < postInfos.length; i++) {
  48.         if(postInfos[i].firstChild.checked) {
  49.             //we do both because one works in 4chanx and one works without.
  50.             postInfos[i].firstChild.checked = false;
  51.             savenums.push("pc".concat(postInfos[i].firstChild.name));
  52.         }
  53.     }
  54.     if(!contains(savenums,op[0].id)) {
  55.        op[0].hidden = true;
  56.        op[0].style.display = 'none';
  57.     }
  58.     for (var i = 0; i < posts.length; i++) {
  59.         if(!contains(savenums,posts[i].id)) {
  60.             posts[i].hidden = true;
  61.         }
  62.     }
  63.     startbutton.setAttribute('value', 'Reveal hidden posts'); // What the enduser sees on button
  64.     startbutton.onclick = function() {
  65.         showPosts();
  66.         onClick();
  67.     };
  68. }
  69.  
  70. function removeSpoilers() {
  71.     var s = document.createElement("style");
  72.     s.innerHTML = "s, s a:not(:hover) {background: none repeat scroll 0% 0% #000000 ! important;color: #ffffff ! important;text-decoration: none;} .spoiler {background: none repeat scroll 0% 0% #000000 ! important;color: #ffffff ! important;text-decoration: none;}";
  73.     s.setAttribute("id", "despoilsheet" + despoilcount);
  74.     document.getElementsByTagName("head")[0].appendChild(s);
  75.     document.getElementById("styleSelector").setAttribute("onchange", "document.getElementById('despoilsheet" + despoilcount + "').disabled = true; setActiveStyleSheet(this.value);document.getElementById('despoilbutton').click(); return false;");
  76.     despoilcount++;
  77.     despoil.setAttribute('value', 'Hide spoilers'); // What the enduser sees on button
  78.     despoil.onclick = function() {
  79.         returnSpoilers();
  80.         onClick();
  81.     };
  82. }
  83.  
  84. function returnSpoilers() {
  85.     var s = document.createElement("style");
  86.     s.innerHTML = "s, s a:not(:hover) {background: none repeat scroll 0% 0% #000000 ! important;color: #000000 ! important;text-decoration: none;} .spoiler {background: none repeat scroll 0% 0% #000000 ! important;color: #000000 ! important;text-decoration: none;}";
  87.     s.setAttribute("id", "despoilsheet" + despoilcount);
  88.     document.getElementsByTagName("head")[0].appendChild(s);
  89.     document.getElementById("styleSelector").setAttribute("onchange", "document.getElementById('despoilsheet" + despoilcount + "').disabled = true; setActiveStyleSheet(this.value); return false;");
  90.     despoilcount++;
  91.     despoil.setAttribute('value', 'Show spoilers'); // What the enduser sees on button
  92.     despoil.onclick = function() {
  93.         removeSpoilers();
  94.         onClick();
  95.     };
  96. }
  97.  
  98. function removeBacklinks() {
  99.         var nodelist = document.getElementsByClassName("backlink-container");
  100.         var backlinks = [];
  101.         for (var i = 0; i < nodelist.length; ++i) {
  102.             backlinks[i] = nodelist[i];
  103.         }
  104.         for (var i = 0; i < backlinks.length; ++i) {
  105.             backlinks[i].hidden = true;
  106.         }
  107.     }
  108. // find the bottom
  109. var bottom = document.getElementsByClassName("absBotText").item(0);
  110. bottom.innerHTML = bottom.innerHTML + '<br>4chan Cap Helper is running, Version: ' + version + ' You can always find the latest version of 4chan Cap helper at <a rel="nofollow" target="_top" href="https://sleazyfork.org/en/scripts/1207-4chan-cap-helper">sleazyfork.org</a><br>';
  111. // init hideposts button
  112. var startbutton = document.createElement('input');
  113. startbutton.setAttribute('type', 'button');
  114. startbutton.setAttribute('value', 'Hide unchecked posts'); // What the enduser sees on button
  115. startbutton.setAttribute('name', 'gottagofast');
  116. startbutton.onclick = function() {
  117.     hidePosts();
  118.     onClick();
  119. };
  120. bottom.appendChild(startbutton);
  121. // init despoil button
  122. var despoil = document.createElement('input');
  123. despoil.setAttribute('id', 'despoilbutton');
  124. despoil.setAttribute('type', 'button');
  125. despoil.setAttribute('value', 'Show spoilers'); // What the enduser sees on button
  126. despoil.setAttribute('name', 'despoiler');
  127. despoil.onclick = function() {
  128.     removeSpoilers();
  129.     onClick();
  130. };
  131. bottom.appendChild(despoil);
  132. // init remove backlinks button
  133. var remBack = document.createElement('input');
  134. remBack.setAttribute('type', 'button');
  135. remBack.setAttribute('value', 'Remove Backlinks'); // What the enduser sees on button
  136. remBack.setAttribute('name', 'rembacklinks');
  137. remBack.onclick = function() {
  138.     removeBacklinks();
  139.     onClick();
  140. };
  141. bottom.appendChild(remBack);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement