[KissAnime] Captcha Solver

Saves initial responses to KissAnime captcha and auto-selects images if it knows the answer. Compatible with any number of images in the captcha.

当前为 2018-07-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         [KissAnime] Captcha Solver
// @namespace    https://greasyfork.org/en/users/193865-westleym
// @author       WestleyM
// @version      2018.07.05
// @icon         http://kissanime.ru/Content/images/favicon.ico
// @description  Saves initial responses to KissAnime captcha and auto-selects images if it knows the answer. Compatible with any number of images in the captcha.
// @grant        none
// @include      http://kissanime.ru/Special/AreYouHuman2*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==

/*
Author Notes:
This is a fork of a script made by user animebro7.  A mirror of the original script can be found here: https://greasyfork.org/en/scripts/368595-kissanime-anime-captcha-solver
It should be noted that the initial solving of the captcha will take quite a long time due to the addition of numbers in the images.
*/


//Global variables
var words = [];
var undefinedWords = [];
var imageSrc = [];
var clickImage = [];
var count = 0;
var formVerify = document.getElementById("formVerify");

if (formVerify === null) {
  console.log("You are on the incorrect answers page.");
}


if (formVerify != null) {  //User is on the regular captcha page
	var imageElements = $("#formVerify").find("img").toArray();  //All images under the "formVerify" form
	var imageNumber = imageElements.length;  //How many images are in the captcha
	
	
	//onclick events
	imageElements.forEach(function(currentImage, imageIndex) {
	  currentImage.onclick = function() {
	    if (!localStorage.getItem("helpword")){ //Saves the solution to local storage
		  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[imageIndex])
		    localStorage.removeItem("helpword");
		  }
	    
	    if (count === 1) {  //Changes text in the alert box
	      alertBoxText.innerText = "Selections complete.  Loading next page. . . .";
	    }
	    
		  if (unknownwords[1] !== undefined && count < 1){ //If there is a word that is not known it will ask for help.  This specific if statement will only activate after you've made your first selection and if the second is unknown.
		    askForHelp(unknownwords[1]);
		    count++;
		  }
	  }
	});
	
	//Message box creation
	var firstDiv = $("#formVerify").find("div").toArray()[0];
	firstDiv.style.cssText = "width:100%;";  //The box holding the information at the top was not wide enough originally
	var thirdPElement = $(firstDiv).find("p").toArray()[2];
	thirdPElement.style.cssText = "opacity:0; height:0px; width:100%;"  //Hides where it lists both selection choices.  This is to insure users select the images in the correct order.
	
	var alertBoxDiv = document.createElement("div");  //Creation of div element which will contain the below text element
	alertBoxDiv.style.cssText = "background:#518203; color:white; height:30px; width:100%; line-height:30px; textAlign:center;"
	
	var alertBoxText = document.createElement("h3");  //Creation of text element which will say the descriptions of images the script doesn't know the answer to
	alertBoxText.innerText = "Checking data. . . .";
	alertBoxText.style.cssText = "background:#518203; color:white; height:100%; width:100%; textAlign:center; font-size: 20px;"
	
	alertBoxDiv.insertAdjacentElement("afterbegin", alertBoxText);  //Inserting "alertBoxText" into "alertBoxDiv" at the top
	thirdPElement.insertAdjacentElement("afterend", alertBoxDiv);  //Placing "alertBoxDiv" at the end of "mainBlock"
	
	
	//Avoid conflicts
	this.$ = this.jQuery = jQuery.noConflict(true);
	$(document).ready(function()
	{
	 	unknownwords = UnknownWords();
	  knownwords = KnownWords();
	  console.log("Unknown words: " + unknownwords);
	  console.log("Known words: " + knownwords);
	  if(unknownwords[0] !== undefined){  //Ask for help with the first unknown word
	  	askForHelp(unknownwords[0]);
	  }
	  knownwords.forEach(function(word){
	    matchfound = 0;
	    console.log("processing known word:" + word)
	    ProcessImages().forEach(function(image,counter){  //Grabs known value from local storage and clicks the corresponding image
	      console.log("counter: " + counter);
	      if(localStorage.getItem(word) == image){
	        console.log("found match for word " + word);
	        matchfound = 1;
	        $("[indexValue='"+counter+"']").click();
	      }else if(counter === imageNumber-1 && matchfound === 0){
	        location.reload();
	      }
	    })
	  })
	});
	
	//Functions
	function askForHelp(word){  //Asks you to select an answer when the script doesn't know.
	  alertBoxText.innerText = "Please select image: " + word;
	  localStorage.setItem("helpWord",word);
	}
	
	function UnknownWords(){  //Finds the words that the script doesn't know the answer to
	  var unknownwords = [];
	  Words().forEach(function(word){
	     if(!localStorage.getItem(word)){  //If the solution isn't found in the local storage, it will be added to the "unknownwords" array
	       	unknownwords.push(word);
	     }
	  });
	  return unknownwords;
	}
	
	function KnownWords(){  //Finds the words that the script knows the answer to
	  var knownWords = [];
	  Words().forEach(function(word){
	     if(localStorage.getItem(word)){  //If solution is found in the local storage, it will be added to the "Knownwords" array
	       	knownWords.push(word);
	     }
	  });
	  return knownWords;
	}
	
	function SaveWord(word, dataurl){
	  if(!localStorage.getItem(word)){
	   	localStorage.removeItem(word);
	    localStorage.setItem(word, dataurl);
	  } else {
	  	localStorage.setItem(word,dataurl);
	  }
	}
	
	function Words(){ //Grabs span elements that are children of the "formVerify" form.  This will include the two sections saying what to select.  Ex: "cat, glasses, 0"
		var pElements = $("#formVerify").find("p").toArray();
	  var finalPElement = pElements[pElements.length-1];
	  var words = $(finalPElement).find("span").toArray();
	  var firstDesc = words[0].innerText;
	  var secondDesc = words[1].innerText;
	  return [firstDesc, secondDesc];
	}
	
	function Images(){
	  return $("[indexValue]").toArray();
	}
	
	function ConvertToDataUrl(img) {
	  var canvas = document.createElement("canvas");
	  canvas.width = img.width;
	  canvas.height = img.height;
	  var ctx = canvas.getContext("2d");
	  ctx.drawImage(img, 0, 0);
	  var dataURL = canvas.toDataURL("image/png");
	  return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
	}
	
	function MinimiseDataUrl(dataUrl,jump) {
	  var a = "";
	  for(var i = 0; i < dataUrl.length; i=i+jump)
	      a += dataUrl.charAt(i);
	  return a;
	}
	
	function ProcessImages()
	{
	  var imagedata = [];
	  Images().forEach(function(image, counter)
	  {
	    dataurl = ConvertToDataUrl(image)
	    imagedata.push(MinimiseDataUrl(MinimiseDataUrl(MinimiseDataUrl(dataurl, 5), 4),3));
	  })
	  return imagedata
	}
}