NoKissReload [CAPTCHA SKIP]

Plays the next Episode without reloading the page

  1. // ==UserScript==
  2. // @name NoKissReload [CAPTCHA SKIP]
  3. // @version 0.23
  4. // @description Plays the next Episode without reloading the page
  5. // @author lolamtisch@gmail.com
  6. // @license Creative Commons; http://creativecommons.org/licenses/by/4.0/
  7. // @match http://kissanime.ru/Anime/*/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_listValues
  12. // @grant GM_deleteValue
  13. // @namespace https://greasyfork.org/users/92233
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. var realUrl = '';
  19. var retries = 0;
  20. $( document ).ready(function() {
  21.  
  22. var nbShortcuts = GM_getValue( 'nbShortcuts', 0 );
  23.  
  24. function noscript(strCode){
  25. var html = $(strCode.bold());
  26. html.find('script').remove();
  27. return html.html();
  28. }
  29.  
  30. function getvideolink(url){
  31. var results = new RegExp('[\?&]' + 's' + '=([^&#]*)').exec(window.location.href);
  32. url += results[0];
  33. $.ajax({
  34. method: "GET",
  35. url: url,
  36. cache: false,
  37. success : function(data, textStatus, xmLHttpRequest){
  38. handleAjaxData(data, url);
  39. },
  40. error: function(data, textStatus, xmLHttpRequest){
  41. window.location.href = url;
  42. }
  43. });
  44. }
  45.  
  46. function handleAjaxData(data, url){
  47. if(data.includes("Are You Human")){
  48. console.log('Captcha');
  49. k = url;
  50. realUrl = url;
  51. capture(data);
  52. return;
  53. }
  54. //console.log(data);
  55. history.pushState({myTag: true}, '', url);
  56. try{
  57. videojs('my_video_1').currentTime("0");
  58. var newlinks = data.split('<select id="slcQualix">')[1].split('</select>')[0];
  59. var link = newlinks.split('"')[1].split('"')[0];
  60. try{
  61. $("#divFileName").html(data.split('divFileName">')[1].split('</div>')[0]);
  62. $("#divDownload").html("");
  63. var urlBefore = $('#my_video_1 video').attr('src');
  64. }catch(e){}
  65. if( $('#slcQualix').height() === null){
  66. $('#my_video_1').before('<select style="display: none;" id="slcQualix"></select>');
  67. }
  68. if( $('#slcQualix').html() === newlinks){
  69. window.location.href = url;
  70. }
  71. $('#slcQualix').html(newlinks);
  72. $("head").trigger( "click" );
  73. if($('#my_video_1').height() === null){
  74. window.location.href = url;
  75. }
  76. videojs('my_video_1').currentTime("0");
  77. $('#slcQualix').trigger("change");
  78. if(urlBefore === $('#my_video_1 video').attr('src')){
  79. SetPlayer(ovelWrap($('#slcQualix').val()));
  80. }
  81. }catch(e){
  82. console.log("error:",e);
  83. window.location.href = url;
  84. }
  85.  
  86. $("#btnPrevious").parent().css("display","initial");
  87. $("#btnNext").parent().css("display","initial");
  88. if($("#selectEpisode")[0].selectedIndex === 0) {
  89. $("#btnPrevious").parent().css("display","none");
  90. }
  91.  
  92. if($("#selectEpisode")[0].selectedIndex === $("#selectEpisode option").size()-1) {
  93. $("#btnNext").parent().css("display","none");
  94. }
  95. }
  96.  
  97. function nextE(){
  98. if(active+1 < link.length){
  99. getvideolink(window.location.href.split('/').slice(0,5).join('/')+'/'+link[active+1]);
  100. active++;
  101. $("#selectEpisode")[0].selectedIndex = active;
  102.  
  103. }
  104. }
  105.  
  106. function previosE(){
  107. if(active > 0){
  108. getvideolink(window.location.href.split('/').slice(0,5).join('/')+'/'+link[active-1]);
  109. active--;
  110. $("#selectEpisode")[0].selectedIndex = active;
  111.  
  112. }
  113. }
  114.  
  115. var link = [];
  116. var active = null;
  117. $("#selectEpisode option").each(function( index ) {
  118. link[index] = $(this).attr("value");
  119. if($("#selectEpisode").attr("value") == $(this).attr("value")){
  120. active = index;
  121. }
  122. });
  123.  
  124. if($("#btnPrevious").height() === null && $("#btnNext").height() !== null){
  125. $("#btnNext").parent().before('<a href="#!"><img id="btnPrevious" src="http://kissanime.ru/Content/images/previous.png" title="Previous episode" border="0"></a>&nbsp;&nbsp;');
  126. $("#btnPrevious").parent().css("display","none");
  127. }
  128.  
  129. if($("#btnNext").height() === null && $("#btnPrevious").height() !== null){
  130. $("#btnPrevious").parent().after('&nbsp;&nbsp;<a href="#!"><img id="btnNext" src="http://kissanime.ru/Content/images/next.png" title="Next episode" border="0"></a>');
  131. $("#btnNext").parent().css("display","none");
  132. }
  133.  
  134. $("#btnNext").parent().attr("href","#!").click(function(){
  135. retries = 0;
  136. nextE();
  137. });
  138.  
  139. $("#btnPrevious").parent().attr("href","#!").click(function(){
  140. retries = 0;
  141. previosE();
  142. });
  143.  
  144. $("#selectEpisode").unbind().change(function(){
  145. retries = 0;
  146. var before = window.location.href.split('/').slice(0,5).join('/')+'/';
  147. active = $("#selectEpisode")[0].selectedIndex;
  148. getvideolink(before+link[active]);
  149. });
  150.  
  151. document.onkeydown = function(evt) {
  152. evt = evt || window.event;
  153. if (evt.keyCode == 78) {
  154. if(nbShortcuts == 1){
  155. nextE();
  156. }
  157. }
  158. if (evt.keyCode == 66) {
  159. if(nbShortcuts == 1){
  160. previosE();
  161. }
  162. }
  163. };
  164.  
  165. if(nbShortcuts == 1){
  166. var check = 'checked';
  167. }else{
  168. var check = '';
  169. }
  170. $('.barContent').after('<input type="checkbox" id="nbShortcuts" '+check+' > Shortcuts ( n = next, b = back )');
  171. $('#nbShortcuts').change(function(){
  172. if($('#nbShortcuts').is(":checked")){
  173. nbShortcuts = 1;
  174. GM_setValue('nbShortcuts', 1);
  175. }else{
  176. nbShortcuts = 0;
  177. GM_setValue('nbShortcuts', 0);
  178. }
  179. });
  180.  
  181. //Rest of code based on KissAnime Multi Downloader
  182. //Author: Anime Bro1
  183. //url: https://greasyfork.org/en/scripts/31080-kissanime-multi-downloader
  184. var images = ["","","","",""];
  185. var words = [];
  186. var k = "";
  187. var eps = [];
  188. var epsName = [];
  189. var epsLinks = [];
  190. var failedLinks = [];
  191.  
  192. var count = 0;
  193. var failedCount = 0;
  194.  
  195. var start = "";
  196. var end = "";
  197. var isText = false;
  198. var isHTML = false;
  199. var isM3U8 = false;
  200. var quality = [];
  201. var failed = true;
  202.  
  203. var animebro;
  204. var max = 1;
  205.  
  206.  
  207. function capture(data){
  208. if(!isBasicJson()){
  209. factoryReset();
  210. getBasicJson();
  211. }
  212. getEP(data);
  213. }
  214.  
  215. function factoryReset(){
  216. var keys = GM_listValues();
  217. for (var i=0; i < keys.length; i++) {
  218. GM_deleteValue(keys[i]);
  219. }
  220. }
  221.  
  222. function isBasicJson(){
  223. return GM_getValue("AnimeBro2",false);
  224. }
  225.  
  226. function getBasicJson(){
  227. var isFirefox = typeof InstallTrigger !== 'undefined';
  228. var isChrome = !!window.chrome && !!window.chrome.webstore;
  229. $("body").append('<div id="CaptchaInfo" style="display:none;width:200px;height:150px;font-size:20px;position:fixed; top: 10px; left:10px; background: red; border-radius: 25px;padding:40px;"><p></p></div>');
  230. $("#CaptchaInfo").show();
  231. $("#CaptchaInfo").find("p").html("First time running, fetching some files... Page will reload.");
  232.  
  233. var msg='';
  234. if(isChrome){
  235. msg = $.ajax({type: "GET", url: "https://cdn.rawgit.com/Eltion/Kissanime-Chaptcha-Auto-Complete/623d627fa2ec94dea00621e406e66088a61b6bff/BasicJson1.json", async: false}).responseText;
  236. }else if(isFirefox){
  237. msg = $.ajax({type: "GET", url: "https://cdn.rawgit.com/Eltion/Kissanime-Chaptcha-Auto-Complete/623d627fa2ec94dea00621e406e66088a61b6bff/BasicJsonFireFox1.json", async: false}).responseText;
  238. }else{
  239. alert("Not Chrome or Firefox. Tryng the chrome database");
  240. msg = $.ajax({type: "GET", url: "https://cdn.rawgit.com/Eltion/Kissanime-Chaptcha-Auto-Complete/623d627fa2ec94dea00621e406e66088a61b6bff/BasicJson1.json", async: false}).responseText;
  241. }
  242. msg = JSON.parse(msg);
  243. for(var i = 0; i < msg.length; i++){
  244. GM_setValue(msg[i].n,msg[i].v);
  245. }
  246. location.reload();
  247. }
  248.  
  249. function getEP(data){
  250. var msg = data;
  251. words = [];
  252. images=["","","","",""];
  253. GetWords(msg,function(){
  254. getImages(msg,function(){
  255. /*count++;
  256. if(count < eps.length){
  257. getEP(eps[count]);
  258. }else{
  259. setTimeout(function(){
  260. AllDone();
  261. }, 5000);
  262. }*/
  263. });
  264. });
  265. }
  266.  
  267. function GetWords(html,callback){
  268. var form = html.split("formVerify")[1].split("</form")[0];
  269. var x = form.match(/(?:<span[^>]*>\s*)([^<]*)/g);
  270. var word1 = x[0].split(">")[1].replace(/\s\s/g,"");
  271. var word2 = x[1].split(">")[1].replace(/\s\s/g,"");
  272. words = [word1,word2];
  273. callback();
  274. }
  275.  
  276. function getImages(html,callback){
  277. //console.log(html);
  278. var items = html.match(/CapImg\??f?=?[^"']*/g);
  279. //console.log(items);
  280. loader(items, loadImage, function () {
  281. Complete();
  282. callback();
  283. });
  284. }
  285.  
  286. function Complete() {
  287. var jj = 0;
  288. var postData = "";
  289. for(var j = 0; j <2; j++){
  290. var w1 = GM_getValue( words[j], false );
  291. if(w1 !== false){
  292. if(w1.includes(" ")){
  293. w1 = w1.split(" ");
  294. }else{
  295. w1 = [w1];
  296. }
  297. for(var k =0; k < w1.length; k++){
  298. for(var i = 0; i < images.length; i++){
  299. if((images[i] === w1[k]) && postData.length < 4){
  300. postData += i+",";
  301. }
  302. }
  303. }
  304. }
  305. }
  306. if(postData.length == 4){
  307. postdata(postData);
  308. console.log("EP Grabed");
  309. }else{
  310. if(retries < 4){
  311. try{
  312. console.log(retries+". try");
  313. retries++;
  314. getvideolink(realUrl.split('&s')[0]);
  315. }catch(e){
  316. window.location.href = realUrl;
  317. }
  318. }else{
  319. window.location.href = realUrl;
  320. }
  321. }
  322. }
  323.  
  324. function postdata(answer){
  325. var data = {reUrl: k, answerCap: answer};
  326. var msg = $.ajax({type: "POST", url: "http://kissanime.ru/Special/AreYouHuman2",data: data ,async: false}).responseText;
  327. //console.log(msg);
  328. //alert();
  329. handleAjaxData(msg, k);
  330. //getLinks(msg);
  331. }
  332.  
  333. function loader(items, thingToDo, allDone) {
  334. if (!items) {
  335. // nothing to do.
  336. return;
  337. }
  338.  
  339. if ("undefined" === items.length) {
  340. // convert single item to array.
  341. items = [items];
  342. }
  343.  
  344. var count1 = items.length;
  345.  
  346. // this callback counts down the things to do.
  347. var thingToDoCompleted = function (items, i) {
  348. count1--;
  349. if (0 === count1) {
  350. allDone(items);
  351. }
  352. };
  353.  
  354. for (var i = 0; i < items.length; i++) {
  355. // 'do' each thing, and await callback.
  356. thingToDo(items, i, thingToDoCompleted);
  357. }
  358. }
  359.  
  360. function loadImage(items, i, onComplete) {
  361. var img = new Image();
  362. var canvas = document.createElement("canvas");
  363. var ctx = canvas.getContext("2d");
  364. var dataURL ="";
  365. var onLoad = function (e) {
  366. canvas.width = img.naturalWidth;
  367. canvas.height = img.naturalHeight;
  368. ctx.drawImage(img, 0, 0);
  369. dataURL = canvas.toDataURL("image/jpeg",0.2);
  370. images[i] = dataURL;
  371. e.target.removeEventListener("load", onLoad);
  372. onComplete(items, i);
  373. };
  374. img.addEventListener("load", onLoad, false);
  375. img.src = "http://kissanime.ru/Special/"+items[i];
  376. }
  377.  
  378. });
  379.  
  380. })();