4Chan WinRAR Finder

Creates a list of all GET's in current thread

  1. // ==UserScript==
  2. // @name 4Chan WinRAR Finder
  3. // @version 1.0
  4. // @description Creates a list of all GET's in current thread
  5. // @author VVind0wM4ker
  6. // @namespace firewaterairanddirt
  7. // @license http://creativecommons.org/licenses/by-nc/4.0/
  8. // @grant none
  9. // @include http*://boards.4chan.org/*/thread/*
  10. // ==/UserScript==
  11.  
  12. function setup () {
  13. if(detect404() == "0") {
  14. //changeThreadTitle(); //Just for test purposes
  15. createBox();
  16. collectGets();
  17. }
  18. else {console.log("...Script not loaded ^");}
  19. }
  20.  
  21. function detect404 () {
  22.  
  23. var get404 = document.querySelectorAll("h2");
  24.  
  25. if (get404.length > 0) {
  26.  
  27. for (var i = 0; i < get404.length; i++) {
  28.  
  29. if (get404[i].innerHTML == "404 Not Found") {
  30.  
  31. console.log("########################################");
  32. console.log("GetScript not loaded cause thread is 404");
  33. console.log("########################################");
  34.  
  35. return 1;
  36. }
  37. }
  38.  
  39. console.log("#################################");
  40. console.log("h2 existing, but thread isn't 404");
  41. console.log("#################################");
  42. return 0;
  43. }
  44. else {return 0;}
  45. }
  46.  
  47. function changeThreadTitle() {
  48.  
  49. var threadTitle = document.getElementsByClassName("boardTitle");
  50. for (i = 0; i < threadTitle.length; i++) {
  51. threadTitle[i].innerHTML = "Modified";
  52. }
  53. }
  54.  
  55. function createBox() {
  56.  
  57. var thread = document.getElementsByClassName("thread")[0];
  58. thread.innerHTML +=
  59. '<div id="getsBox" class="reply" style="height: auto; width: 222px; padding: 5px 5px 10px; float: right;">' +
  60. '<div id="getsHeader" style="height: auto; width: 100%; padding: 0px 0px 10px; font-weight: bold; color: black; text-align: center;">' +
  61. 'GET\'s in this Thread' +
  62. '</div>' +
  63. '<div id="getsContainer" style="width: 100%; text-align: center;">' +
  64. '<div id="Dubs" class="get">' +
  65. 'Dubs<br>' +
  66. '</div>' +
  67. '<div id="Trips" class="get">' +
  68. '<br>Trips<br>' +
  69. '</div>' +
  70. '<div id="Quads" class="get">' +
  71. '<br>Quads<br>' +
  72. '</div>' +
  73. '<div id="Quints" class="get">' +
  74. '<br>Quints<br>' +
  75. '</div>' +
  76. '<div id="WinRAR" class="get">' +
  77. '<br>WinRAR<br>' +
  78. '</div>' +
  79. '</div>' +
  80. '</div>';
  81.  
  82. //hide all categories
  83. var categories = document.getElementsByClassName("get");
  84. for (var i = 0; i < categories.length; i++) {
  85. categories[i].style.display = "none";
  86. categories[i].style.margin = "5px 0px";
  87. }
  88.  
  89. var getsBox = document.getElementById("getsBox");
  90. thread.insertBefore(getsBox, thread.childNodes[0]);
  91. }
  92.  
  93. function collectGets () {
  94. var getscontainer = document.getElementById("getsContainer");
  95. var posts = document.querySelectorAll("a[title='Reply to this post']");
  96. var post = document.getElementByClassName;
  97. var prevnum = null;
  98.  
  99. for (var i = 0; i < posts.length; i++) {
  100.  
  101. var postnum = posts[i].innerHTML;
  102.  
  103. if (postnum != prevnum) {
  104.  
  105. var postnum_c = postnum;
  106. var gettype = 1;
  107.  
  108. //ANALYSE
  109. while (1) {
  110.  
  111. var postnum_digit1 = postnum_c.substr(postnum_c.length - 2, 1);
  112. var postnum_digit2 = postnum_c.substr(postnum_c.length - 1, 1);
  113.  
  114. if (postnum_digit1 == postnum_digit2) {gettype++;}
  115. else {break;}
  116. if (postnum_c.length <= 2) {break;}
  117. postnum_c = postnum_c.substr(0, postnum_c.length - 1);
  118. }
  119.  
  120. if (gettype >= 2) { //gettype >= 2 adds all dubs or higher - change to filter
  121. addGets(gettype, postnum);
  122. //highlightGet (gettype, postnum, posts[i]); //Highlighting currently disabled, because I'm not satisfied with it
  123. //highlightGet (gettype, postnum, posts[i+1]); //yes my english is kill
  124. }
  125. prevnum = postnum;
  126. }
  127. }
  128. }
  129.  
  130. function addGets (gettype, postnum) {
  131. if (gettype <= 1) {return;}
  132. if (gettype == 2) {gettype = "Dubs"}
  133. if (gettype == 3) {gettype = "Trips"}
  134. if (gettype == 4) {gettype = "Quads"}
  135. if (gettype == 5) {gettype = "Quints"}
  136. if (gettype >= 5) {gettype = "WinRAR"}
  137.  
  138. document.getElementById(gettype).style.display = "inline";
  139. document.getElementById(gettype).innerHTML += '<a class="quotelink" href="#p' + postnum + '">' + postnum + '</a><br>';
  140. }
  141.  
  142. function highlightGet (gettype, postnum, getHandle) { //currently disabled (->129)
  143. var postnum_pre = postnum.substr(0, postnum.length - gettype);
  144. var postnum_post = postnum.substr(postnum.length - gettype);
  145. getHandle.innerHTML = "<a>" + postnum_pre + "<a style='background-color: rgb(255,153,153);'>" + postnum_post + "</a></a>";
  146. }
  147.  
  148. window.onload = function () {setup();};