Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Ecchi captcha
- // @namespace Violentmonkey Scripts
- // @match https://iichan.hk/*
- // @match http://iichan.hk/*
- // @grant none
- // @version 1.0
- // @author -
- // @description 01/04/2022, 20:12:48
- // ==/UserScript==
- // user-defined variables, put your favorite tags here
- var tags = ["solo","1girl","panties"];
- var showExplicit = false;
- var thumbnailSize = 200;
- var postsPerPage = 100;
- var randomPage = Math.floor(Math.random()*1000); // random page
- var url = "https://danbooru.donmai.us/posts.json?page="+randomPage+"&limit="+postsPerPage+"&only=id,large_file_url,image_width,image_height&tags=";
- var posts;
- var captcha = document.getElementById("captcha").parentElement;
- function getPosts(){
- url += tags.join("+");
- if (!showExplicit) url+="&rating=sq";
- var request = new XMLHttpRequest();
- request.onreadystatechange = function(e)
- {
- if (request.readyState == 4)
- {
- posts = JSON.parse(request.responseText).filter(p=>p.large_file_url != null);
- var img = posts[Math.floor(Math.random()*posts.length)];
- updateCaptcha(img); // random image on the page
- captcha.addEventListener('click', getRandomImage, false);
- }
- }
- request.open('GET', url, true);
- request.setRequestHeader('Accept', 'text/plain');
- request.send(null);
- }
- function updateCaptcha(image){
- var ratio = image.image_width/image.image_height;
- var thumbWidth, thumbHeight;
- if (ratio > 1) { // horizontal image
- thumbWidth = thumbnailSize+"px";
- thumbHeight = Math.floor(thumbnailSize/ratio)+"px";
- }
- else{
- thumbHeight = thumbnailSize+"px";
- thumbWidth = Math.floor(thumbnailSize*ratio)+"px";
- }
- var img = new Image();
- img.onload = function() {
- captcha.setAttribute("style", "display: block; width:"+thumbWidth+";height:"+thumbHeight+"; background-size: "+thumbWidth+" "+thumbHeight+";background-image: url('"+img.src+"');");
- }
- img.src = image.large_file_url;
- if (img.complete) img.onload();
- }
- function getRandomImage(){
- captcha.style.opacity = "0.5";
- updateCaptcha(posts[Math.floor(Math.random()*posts.length)]);
- captcha.style.opacity = "1";
- }
- window.addEventListener('load', getPosts, false);
Add Comment
Please, Sign In to add comment