Guest User

Untitled

a guest
Apr 1st, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Ecchi captcha
  3. // @namespace   Violentmonkey Scripts
  4. // @match       https://iichan.hk/*
  5. // @match       http://iichan.hk/*
  6. // @grant       none
  7. // @version     1.0
  8. // @author      -
  9. // @description 01/04/2022, 20:12:48
  10. // ==/UserScript==
  11.  
  12. // user-defined variables, put your favorite tags here
  13. var tags = ["solo","1girl","panties"];
  14. var showExplicit = false;
  15. var thumbnailSize = 200;
  16. var postsPerPage = 100;
  17.  
  18. var randomPage = Math.floor(Math.random()*1000); // random page
  19. var url = "https://danbooru.donmai.us/posts.json?page="+randomPage+"&limit="+postsPerPage+"&only=id,large_file_url,image_width,image_height&tags=";
  20.  
  21. var posts;
  22. var captcha = document.getElementById("captcha").parentElement;
  23.  
  24. function getPosts(){
  25.   url += tags.join("+");
  26.   if (!showExplicit) url+="&rating=sq";  
  27.  
  28.   var request = new XMLHttpRequest();
  29.         request.onreadystatechange = function(e)
  30.         {
  31.             if (request.readyState == 4)
  32.             {
  33.         posts = JSON.parse(request.responseText).filter(p=>p.large_file_url != null);
  34.         var img = posts[Math.floor(Math.random()*posts.length)];
  35.         updateCaptcha(img); // random image on the page
  36.         captcha.addEventListener('click', getRandomImage, false);
  37.             }
  38.         }
  39.    request.open('GET', url, true);
  40.      request.setRequestHeader('Accept', 'text/plain');
  41.      request.send(null);
  42. }
  43.  
  44. function updateCaptcha(image){
  45.   var ratio = image.image_width/image.image_height;
  46.   var thumbWidth, thumbHeight;
  47.   if (ratio > 1) { // horizontal image
  48.     thumbWidth = thumbnailSize+"px";
  49.     thumbHeight = Math.floor(thumbnailSize/ratio)+"px";
  50.   }
  51.   else{
  52.     thumbHeight = thumbnailSize+"px";
  53.     thumbWidth = Math.floor(thumbnailSize*ratio)+"px";
  54.   }
  55.   var img = new Image();
  56.   img.onload = function() {
  57.     captcha.setAttribute("style", "display: block; width:"+thumbWidth+";height:"+thumbHeight+"; background-size: "+thumbWidth+" "+thumbHeight+";background-image: url('"+img.src+"');");
  58.   }
  59.   img.src = image.large_file_url;
  60.   if (img.complete) img.onload();
  61. }
  62.  
  63. function getRandomImage(){
  64.   captcha.style.opacity = "0.5";
  65.   updateCaptcha(posts[Math.floor(Math.random()*posts.length)]);
  66.   captcha.style.opacity = "1";
  67. }
  68.  
  69. window.addEventListener('load', getPosts, false);
Add Comment
Please, Sign In to add comment