Sleazy Fork is available in English.

better search rule34

08.01.2022, 13:40:04

  1. // ==UserScript==
  2. // @name better search rule34
  3. // @namespace Violentmonkey Scripts
  4. // @match https://rule34.xxx/index.php
  5. // @grant none
  6. // @version 1.0
  7. // @require https://code.jquery.com/jquery-3.5.1.min.js
  8. // @author -
  9. // @description 08.01.2022, 13:40:04
  10. // ==/UserScript==
  11.  
  12. async function main(){
  13. console.log("better search rule34");
  14. var tags = $("input[name='tags']").val().split(' ');
  15. for(var i = 0; i < tags.length; i++){
  16. if(tags[i].split("||").length > 1){
  17. $("div.image-list").empty()
  18. console.log(tags[i].split("||"));
  19. var normalTags = "";
  20. for(var j = 0; j < tags.length; j++){
  21. if(tags[j].includes("||")){
  22. continue;
  23. }
  24. normalTags += tags[j] + " ";
  25. }
  26. console.log(normalTags);
  27. for(var x = 0; x < tags[i].split("||").length; x++){
  28. var tag = normalTags + tags[i].split("||")[x];
  29. var postCount = await getPostCount(tag);
  30. console.log("POST COUNT: " + tag, postCount);
  31. var div = document.createElement("div");
  32. var content = document.createElement("div");
  33. content.id = tag;
  34. var header = document.createElement("h3");
  35. header.innerHTML = tag + " >> " + postCount;
  36. header.style.backgroundColor = "#e74c3c";
  37. header.onclick = function(){
  38. if(this.nextSibling.style.display != "none"){this.nextSibling.style.display = "none"}else{this.nextSibling.style.display = "block";}
  39. };
  40. div.appendChild(header);
  41. div.appendChild(content);
  42. document.getElementsByClassName("content")[0].appendChild(div);
  43. var imgDir = [];
  44. for(var k = 0; k <= postCount; k += 42){
  45. //addImagesFromUrl("https://rule34.xxx/index.php?page=post&s=list&tags=" + tag + "&pid=" + k, content);
  46. imgDir.push(getImagesFromUrl("https://rule34.xxx/index.php?page=post&s=list&tags=" + tag + "&pid=" + k));
  47. header.innerHTML = tag + " >> " + k + " loading...";
  48. }
  49. const result = await Promise.all(imgDir);
  50. console.log(result);
  51. header.innerHTML = tag + " >> " + k + " Done";
  52. for(var k = 0; k < result.length; k++){
  53. for(var j = 0; j < result[k].images.length; j++){
  54. content.appendChild(result[k].images[j]);
  55. }
  56. }
  57. }
  58. }
  59. }
  60. /*
  61. for(var i = 0; i < tags.length; i++){
  62. console.log(tags[i]);
  63. console.log(tags);
  64. var postCount = await getPostCount(tags[i]);
  65. console.log(postCount);
  66. for(var j = 0; j <= postCount; j += 42){
  67. console.log("requesting: ", "https://rule34.xxx/index.php?page=post&s=list&tags=" + tags[i] + "&pid=" + j);
  68. addImagesFromUrl("https://rule34.xxx/index.php?page=post&s=list&tags=" + tags[i] + "&pid=" + j);
  69. await sleep(10000);
  70. }
  71. }*/
  72. };
  73.  
  74. async function getPostCount(tags){
  75. var postCount = 0;
  76. var iframe = document.createElement("iframe");
  77. iframe.id = "ifream";
  78. iframe.src = "https://rule34.xxx/index.php?page=post&s=list&tags=" + tags;
  79. iframe.onload = function() {
  80. postCount = $("#ifream").contents().find('a[alt="last page"]')[0].href.split("pid=")[1];
  81. iframe.parentNode.removeChild(iframe);
  82. }
  83. document.body.appendChild(iframe);
  84. while(postCount == 0){
  85. await sleep(100);
  86. }
  87. return postCount;
  88. }
  89. function addImagesFromUrl(url, element = null){
  90. if(element == null){element = document.getElementsByClassName("content")[0]};
  91. var ifream = document.createElement("iframe");
  92. ifream.src = url;
  93. ifream.onload = function() {
  94. var images = ifream.contentWindow.document.getElementsByTagName("img");
  95. var header = document.createElement("h6");
  96. header.innerHTML = url;
  97. element.appendChild(header, document.getElementById("paginator"));
  98. /*for(i = images.length-1; i >= 0; i--){
  99. if(images[i].parentNode.parentNode.tagName == "SPAN"){
  100. document.getElementById("paginator").parentNode.insertBefore(images[i].parentNode.parentNode, document.getElementById("paginator"));
  101. }
  102. }*/
  103. for(i = 0; i < images.length; i++){
  104. if(images[i].parentNode.parentNode.tagName == "SPAN"){
  105. element.appendChild(images[i].parentNode.parentNode.cloneNode(true), document.getElementById("paginator"));
  106. }
  107. }
  108. ifream.parentNode.removeChild(ifream);
  109. }
  110. document.body.appendChild(ifream);
  111. }
  112. async function getImagesFromUrl(url){
  113. var outimages = [];
  114. var done = false;
  115. var ifream = document.createElement("iframe");
  116. ifream.src = url;
  117. ifream.onload = function() {
  118. var images = ifream.contentWindow.document.getElementsByTagName("img");
  119. for(i = 0; i < images.length; i++){
  120. if(images[i].parentNode.parentNode.tagName == "SPAN"){
  121. outimages.push(images[i].parentNode.parentNode.cloneNode(true));
  122. }
  123. }
  124. done = true;
  125. ifream.parentNode.removeChild(ifream);
  126. }
  127. document.body.appendChild(ifream);
  128. while(done == false){
  129. await sleep(100);
  130. }
  131. return {pid : url.split('&pid=')[1],
  132. images : outimages};
  133. }
  134.  
  135. function sleep(milliseconds) {
  136. return new Promise(resolve => setTimeout(resolve, milliseconds));
  137. }
  138. $( document ).ready(function() {
  139. if ( window.location == window.parent.location ){ main(); }
  140. });
  141.  
  142.  
  143.