NoKissReload [CAPTCHA SKIP]

Plays the next Episode without reloading the page

当前为 2017-07-03 提交的版本,查看 最新版本

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