// ==UserScript==
// @name NoKissReload
// @version 0.16
// @description Plays the next Episode without reloading the page
// @author lolamtisch@gmail.com
// @license Creative Commons; http://creativecommons.org/licenses/by/4.0/
// @match http://kissanime.ru/Anime/*/*
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// @namespace https://greasyfork.org/users/92233
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
$( document ).ready(function() {
var nbShortcuts = GM_getValue( 'nbShortcuts', 0 );
function noscript(strCode){
var html = $(strCode.bold());
html.find('script').remove();
return html.html();
}
function getvideolink(url){
url += "&s=beta";
$.ajax({
method: "GET",
url: url,
cache: false,
success : function(data, textStatus, xmLHttpRequest){
//console.log(data);
history.pushState({myTag: true}, '', url);
try{
videojs('my_video_1').currentTime("0");
var newlinks = data.split('')[0];
var link = newlinks.split('"')[1].split('"')[0];
try{
$("#divFileName").html(data.split('divFileName">')[1].split('')[0]);
$("#divDownload").html("");
var urlBefore = $('#my_video_1 video').attr('src');
}catch(e){}
if( $('#slcQualix').height() === null){
$('#my_video_1').before('');
}
if( $('#slcQualix').html() === newlinks){
window.location.href = url;
}
$('#slcQualix').html(newlinks);
$("head").trigger( "click" );
if($('#my_video_1').height() === null){
window.location.href = url;
}
videojs('my_video_1').currentTime("0");
$('#slcQualix').trigger("change");
if(urlBefore === $('#my_video_1 video').attr('src')){
SetPlayer(ovelWrap($('#slcQualix').val()));
}
}catch(e){
console.log("error:",e);
window.location.href = url;
}
$("#btnPrevious").parent().css("display","initial");
$("#btnNext").parent().css("display","initial");
if($("#selectEpisode")[0].selectedIndex === 0) {
$("#btnPrevious").parent().css("display","none");
}
if($("#selectEpisode")[0].selectedIndex === $("#selectEpisode option").size()-1) {
$("#btnNext").parent().css("display","none");
}
},
error: function(data, textStatus, xmLHttpRequest){
window.location.href = url;
}
});
}
function nextE(){
if(active+1 < link.length){
getvideolink(window.location.href.split('/').slice(0,5).join('/')+'/'+link[active+1]);
active++;
$("#selectEpisode")[0].selectedIndex = active;
}
}
function previosE(){
if(active > 0){
getvideolink(window.location.href.split('/').slice(0,5).join('/')+'/'+link[active-1]);
active--;
$("#selectEpisode")[0].selectedIndex = active;
}
}
var link = [];
var active = null;
$("#selectEpisode option").each(function( index ) {
link[index] = $(this).attr("value");
if($("#selectEpisode").attr("value") == $(this).attr("value")){
active = index;
}
});
if($("#btnPrevious").height() === null && $("#btnNext").height() !== null){
$("#btnNext").parent().before('
');
$("#btnPrevious").parent().css("display","none");
}
if($("#btnNext").height() === null && $("#btnPrevious").height() !== null){
$("#btnPrevious").parent().after('
');
$("#btnNext").parent().css("display","none");
}
$("#btnNext").parent().attr("href","#!").click(function(){
nextE();
});
$("#btnPrevious").parent().attr("href","#!").click(function(){
previosE();
});
$("#selectEpisode").unbind().change(function(){
var before = window.location.href.split('/').slice(0,5).join('/')+'/';
active = $("#selectEpisode")[0].selectedIndex;
getvideolink(before+link[active]);
});
document.onkeydown = function(evt) {
evt = evt || window.event;
if (evt.keyCode == 78) {
if(nbShortcuts == 1){
nextE();
}
}
if (evt.keyCode == 66) {
if(nbShortcuts == 1){
previosE();
}
}
};
if(nbShortcuts == 1){
var check = 'checked';
}else{
var check = '';
}
$('.barContent').after(' Shortcuts ( n = next, b = back )');
$('#nbShortcuts').change(function(){
if($('#nbShortcuts').is(":checked")){
nbShortcuts = 1;
GM_setValue('nbShortcuts', 1);
}else{
nbShortcuts = 0;
GM_setValue('nbShortcuts', 0);
}
});
});
})();