[KissAnime] Captcha Solver

Saves initial responses to KissAnime captcha and auto-selects images if it knows the answer. Updated for the new six image captcha.

目前為 2018-06-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [KissAnime] Captcha Solver
// @namespace    https://greasyfork.org/en/users/193865-westleym
// @author       WestleyM
// @version      2018.06.30
// @icon         http://kissanime.ru/Content/images/favicon.ico
// @description  Saves initial responses to KissAnime captcha and auto-selects images if it knows the answer. Updated for the new six image 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 ankit16-19.  The original script can be found here: https://greasyfork.org/en/scripts/368595-kissanime-anime-captcha-solver
The purpose of this version is to allow support for the new captcha, with 6 images rather than the old 4.  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.  My estimate is about 100 episodes.
Also take note of the fact that occasionally you may have a captcha with 8 images.  Either refresh the page or manually solve the captcha.
Support for any number of images will be added at a later date.  As of now, this script is only a light modification of its parent script.
In the future I may also include the captcha solutions in the code, I still haven't decided since it will take up a large chunk of the file.
Commenting of this code is sparse but I will improve it later.

If ankit16-19 would like this removed I will delete it.
*/



//Custom HTML
$("#formVerify").append("<br>")

//First Button
var input=document.createElement("input");
input.id = "image1"
input.type="button";
input.value="Image1";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[0])
    localStorage.removeItem("helpword");
  }
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }
  $("[indexValue=0]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input);

//Second Button
var input=document.createElement("input");
input.id = "image2"
input.type="button";
input.value="Image2";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[1])
    localStorage.removeItem("helpword");
  }  
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }  
  $("[indexValue=1]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input);

//Third Button
var input=document.createElement("input");
input.id = "image3"
input.type="button";
input.value="Image3";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[2])
    localStorage.removeItem("helpword");
  } 
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }  
  $("[indexValue=2]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input);

//Fourth Button
var input=document.createElement("input");
input.id = "image4"
input.type="button";
input.value="Image4";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[3])
    localStorage.removeItem("helpword");
  }
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }  
  $("[indexValue=3]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input); 


//Fifth Button
var input=document.createElement("input");
input.id = "image5"
input.type="button";
input.value="Image5";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[4])
    localStorage.removeItem("helpword");
  }
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }  
  $("[indexValue=4]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input);


//Sixth Button
var input=document.createElement("input");
input.id = "image6"
input.type="button";
input.value="Image6";
input.onclick = function(){
  if(!localStorage.getItem("helpword")){
  	localStorage.setItem(localStorage.getItem("helpWord"),ProcessImages()[5])
    localStorage.removeItem("helpword");
  }
  if(unknownwords[2] !== undefined && count < 1){
    askForHelp(unknownwords[2]);
    count++;
  }  
  $("[indexValue=5]").click();
}
input.setAttribute("style", "font-size:18px;");
document.getElementById("formVerify").appendChild(input);



//Global variables
var words = [];
var undefinedWords = [];
var imageSrc = [];
var clickImage = [];
var count = 0;



//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);
  // ask user for help with first word
  if(unknownwords[1] !== undefined){
  	askForHelp(unknownwords[1]);
  }
  knownwords.forEach(function(word){
    matchfound = 0;
    console.log("processing known word:" + word)
    // get value from storage and click the corresponsding image;
    ProcessImages().forEach(function(image,counter){
      console.log("counter: " + counter);
      if(localStorage.getItem(word) == image){
        console.log("found match for word " + word);
        matchfound = 1;
        $("[indexValue='"+counter+"']").click();
      }else if(counter === 5 && matchfound === 0){
        location.reload();
      }
    })
    
  })  

});

function askForHelp(word){
  alert("We need help for the word:" + word);
  localStorage.setItem("helpWord",word);
}

function UnknownWords(){
  var unknownwords = [];
  Words().forEach(function(word){
     if(!localStorage.getItem(word)){
       	unknownwords.push(word);
     }
  });
  return unknownwords;
}
function KnownWords(){
  var Knownwords = [];
  Words().forEach(function(word){
     if(localStorage.getItem(word)){
       	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(){
    var words = $("#formVerify").find("span").toArray();
    var First = words[0].innerText;
    var Second = words[1].innerText;
    var Third = words[2].innerText;
    return [First, Second, Third];
}

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
}